Skip to content

Instantly share code, notes, and snippets.

@dmlogv
Last active July 31, 2020 13:57
Show Gist options
  • Save dmlogv/84f0a768a60b89a415f456f75a8ff023 to your computer and use it in GitHub Desktop.
Save dmlogv/84f0a768a60b89a415f456f75a8ff023 to your computer and use it in GitHub Desktop.
Habr markdown article preprocessor

To prepare an article to habr.com publishing use following rules:

  • Start an artile with H1 header:

    # Самые талантливые программисты на `sed` в 2020 году #
    
    ...
  • Follow the article header with special quotes for the Tags, Hubs and optional Tutorial mark:

    # ООП на `sed` #
    
    > Hubs: Ненормальное программирование, POSIX
    
    > Tags: sed, ооп
    
    > Tutorial 
    
    ...
  • Preceed specific Habr tags with a TODO-HABR: mark. E.g.:

    Что обычно видишь, когда гуглишь слово Airflow / Wikimedia Commons
    
    TODO-HABR: <cut />
    
    В папку ./dags мы будет складывать наши файлы с описанием дагов. Они будут подхватываться на лету, поэтому передёргивать весь стек после каждого чиха не нужно.
    
    TODO-HABR: <spoiler title="docker-compose.yml">
    version: '3.4'
    
    x-airflow-config: &airflow-config
      AIRFLOW__CORE__DAGS_FOLDER: /dags
      AIRFLOW__CORE__EXECUTOR: CeleryExecutor
    
    TODO-HABR: </spoiler>
  • Store pictures in the pics/ subfolder (separate for any articles) and follow every link to the local picture with a link to the uploaded one:

    Посмотрите на этот чудесный скриншот!
    ![](/pics/my_awesome_screnshot.png)
    ![](https://habrastorage.org/webt/lf/59/ve/lf50vefopsudfwc2ynlpomu_ntt.png)

Than you can use the ./prep.sed:

$ ./prep.sed articel/README.md

for console preview. Or

$ ./prep.sed -i articel/README.md

To change a source file.

Be careful, -i flag is undone! Don't forget to commit your sources!

#!/usr/local/bin/gsed -E -f
# Remove main header
0,/^#\s+/{//d}
# Remove sections
/^> Hubs:/d
/^> Tags:/d
/^> Tutorial/d
# Remove specific tags todo's
s/TODO-HABR:\s*//g
# Remove local picture references
/!\[\]\(pics\//d
# Remove whitespace at start of the file
/./,$!d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment