Habr Converter: to make it easy

Surely many of you at least once used a hub converter, which is officially recommended by the Habr administration - https://shirixae.imtqy.com/habraconverter-v2/ . A few years ago it was created by a habrovchaninmeta4, and then finalized Shirixae. The principle is simple: open the Google Account with the post, Ctrl-A, Ctrl-C and paste it into the converter window. Press the button “Convert” and get a ready-made code for layout, which can be inserted into the Habr editor and published. Just before that, you need to go over and fix some little things.

And everything would be fine if you have to make up not too often. Or posts are small, uncomplicated. But if you are doing a lot of typesetting, and the posts have pictures, tables, and pieces of code, then you have to do a routine from time to time: insert the necessary empty lines and remove the extra ones, replace the tags <surce>with <cde>, etc. etc. We decided to spend a day, then fly in an hour, and finished the converter.

The new version is here , and under the cut is a list of improvements.

The converter code is small, about 300 lines. We did not set ourselves the task of deeply reworking it, just to work along, so that after the converter it would be less to rule our hands. So we immediately draw your attention: in our version there are a lot of crutches and hardcode, and this completely suits us - we have achieved our goal, and we were not going to refactor for the sake of beauty and clarity.

Of course, when you break into someone else’s code and redo something, it’s easier to make bugs easily. Initially, the list of edits was as follows:

  1. After paragraphs, you need to do two transfers so that an empty line appears between paragraphs.
  2. Same thing with pictures: tags <img>should be separated by blank lines at the top and bottom.
  3. After you </surce>need only one line break (without an empty line).
  4. </li> , , . 
  5. </a> .
  6. </tble> .
  7. </h> , .
  8. , .
  9. </ul> , .
  10. </blockqoute>.


  • , <cde>, <surce> ( ). 
  • , <tble></tble> <cde>, <surce>.
  • <b> <strng>.
  • Forced bold text and list tags were removed from the headings - those who need it will be inserted by hand, but usually this is superfluous.

Corrected such bugs: 

  • Do not process the content <>, it should always remain unchanged. Example : the code <img src="https://habrastorage.org/getpro/habr/post_images/208/1cc/1fa/2081cc1fa6dbebbbb6ddd4108512ff5b.png" align="cnter">in the text should remain the same after conversion.
  • There is some kind of conflict when they adjoin <ul>and <h>- unnecessary empty lines arise between them.
  • In the process, our converter suddenly began to insert extra lines where they should not be. Then at some point extra quotes-fir-trees began to be added to the image tags, I also had to cut it out:<img src="«https://habrastorage.org/getpro/habr/post_images/208/1cc/1fa/2081cc1fa6dbebbbb6ddd4108512ff5b.png»" lign="«center»">
  • They overcame unexpected behavior when the attribute was inserted in the first image in the layout lign="center", and in all the others lign="middle".

Oh yes, and we added the Copy button above the conversion window. If you ever tried to highlight the result on a smartphone to copy, then you will understand that this is almost the best of our improvements.

Now, after our converter, we have to significantly reduce minor issues, for which a lot of time was spent on our monthly publication volume. Like all previous versions, the converter is available to everyone - pull requests and issue are welcome.

Source: https://github.com/AloneCoder/habrconverter 

Muzzle: https://alonecoder.imtqy.com/habrconverter/

All Articles