Preparation of articles for Habr: Markdown extension + syntax highlighting + image loading

    Description

    I present to you the extension of the "human" Markdown markup language for use on the Habr. The main goals:
    • Replace “human-readable” but not “human-readable” HTML with Markdown.
    • Provide support for advanced Habr markup.
    • Automate the loading of images and the insertion of their URL into the article.
    • Add syntax highlighting.
    Using
    1. Download and unpack the archive into a separate folder
    2. We write the article in the article.txt file
    3. Copy the desired images to the folder
    4. We type make copy, we get the HTML text of the article in the article.html file and in the clipboard
    5. We post on Habr
    Kit Composition
    • habraml.py - Markdown advanced markup to HTML converter.
    • Makefile - commands for creating HTML, upload images and more.
    • article.txt is the text of this article as an example.
    Requirements
    • python-markdown
    • python-pygments
    • photo-upload
    • xsel
    • make
    Make goals
    • make - upload images and generate HTML
    • make upload-images- upload images to imageshack.us
    • make copy - upload images, generate and copy HTML to the clipboard
    Download
    habraml.zip

    Standard Markdown Markup

    Official Syntax Documentation
    Headings
    First level heading
    ==========================
    # Also the first level heading #
    # Or so
    Second level heading
    ------------------------
    ## Also second
    ### Third
    
    Text selection
    plain text
    * inclined *, _also inclined_,
    ** bold **, __ also bold__,
    `code`
    
    plain text, oblique , also oblique , bold , also bold ,код
    Quote
    > Acquaintances-these are people, just in case, calling you a fool.
    > Good friends can already tell you a bad joke.
    > Friends are those who really know some real nasty things about you.
    > Don Aminado
    
    Acquaintances are people, just in case, calling you a fool. Good friends can already tell you a bad joke. Friends are those who really know some real nasty things about you. Don Aminado
    Or so:
    > The idea, perhaps, has a greater independent value,
    the less he believes in her from whom she comes, for then she does not
    reflects his desires, needs and prejudices ...
    Oscar Wilde
    
    The idea, perhaps, has the greater independent value, the less the one who comes from it believes in it, because then it does not reflect its desires, needs and prejudices ... Oscar Wilde
    References
    [link to habrahabr] (http://habrahabr.ru)
    
    link to habrahabr
    List
    Unnumbered (you can use "-", "+" and "*"):
    - item1
    - item2
    
    • item1
    • item2
    Numbered (you can use one number for all elements):
    1. First
    2. Second
    
    1. First
    2. Second
    Horizontal line
    --------------------------
    

    Picture
    ! [Habr logo] (https://habrastorage.org/getpro/habr/post_images/142/895/3aa/1428953aa0d7b50586df81c2bbf78b53.gif)
    
    Habr logo

    Advanced formatting

    Headings
    Heading levels are shifted by 3, as required by the Habr. Those. headings start at level four.
    Habracat
    -x ----------------------------
    -x ---- Text instead of "Read more"
    
    Link to Habrauser
    @kriomant
    
    kriomant
    Strikethrough
    ~~ strikethrough text ~~
    
    strikethrough text
    Local images
    If the image address does not start with “http: //”, then the image is considered local. In this case, two lines are read from the file “image_address.address”: the first is the address of the thumbnail image, the second is the address of the page for viewing the full-size image. A small copy of the image with a link to the original is inserted into the page code. Files “* .address” are automatically generated by the assembly script when uploading images.
    Syntax highlighting
    @ python @
    print ('string')
    for item in (2, 3, 4):
        print (item)
    
    turns into:
    print ('string')
    for  item  in  (2, 3, 4):
        print (item)

    Display Issues

    The Habr parser is a very strange and unpredictable thing. For some reason, it cuts out the tags “p”, does not display “hr”, parses links incorrectly and even puts exclamation marks on itself . I applied the most necessary hacks without which nothing is shown at all. In the future, I consider it incorrect to correct the code for various glitches: the parser will probably be corrected in a year or two, but no one will redo the text of the article.

    Also popular now: