From 4be35019391cf1b1fe0b1aa9df07edb75f110910 Mon Sep 17 00:00:00 2001 From: Joshua Seigler Date: Thu, 17 Oct 2019 16:23:53 -0400 Subject: [PATCH] Add Readme.io conversion script --- scripts/pipe-convert-for-readme | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 scripts/pipe-convert-for-readme diff --git a/scripts/pipe-convert-for-readme b/scripts/pipe-convert-for-readme new file mode 100755 index 00000000..08b31625 --- /dev/null +++ b/scripts/pipe-convert-for-readme @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# To use this script, pipe the contents of a MD file into it. +# It will output that content reformatted for Readme. + +# Examples: +# Reformat the contents of the clipboard +# xclip -o | ./pipe-convert-for-readme | xclip -selection clipboard +# +# Reformat a file and write it to a new file +# cat ../_includes/devdoc/guide_block_chain.md | ./pipe-convert-for-readme > ../_readme/guide_block_chain.md + +perl -0 \ +-pe "s///gs;" \ +-pe "s/\{% comment %\}.+?{% endcomment %\}//gs;" \ +-pe "s/\{% include helpers\/subhead-links\.md %\}//g;" \ +-pe "s/\{% (end)?autocrossref %\}//gs;" \ +-pe "s/\{% assign filename=.+? %\}//g;" \ +-pe "s/\{:\.no_toc\}//g;" \ +-pe "s/\[([^\]]+)\]\[.+?\.term\}/<>/g;" \ +-pe "s/\{% highlight ([^%]+) %\}(.+?\n){% endhighlight %\}/\`\`\` \1\2\`\`\`/gs;" \ +-pe "s/<<([^>]+)\n([^>]+)>>/<<\1 \2>>/gs;" \ +-pe "s!\(/img!(https://dash-docs.github.io/img!g;" \ +-pe "s/{% itemplate ntpd1 %}/Name | Type | Presence | Description\n--- | --- | --- | ---/g;" \ +-pe "s/\n+- n: \"(.*?)\"\s+t: \"(.*?)\"\s+p: \"(.*?)\"\s+d: \"(.*?)\"/\n\1 | \2 | \3 | \4/g;" \ +-pe "s/{% enditemplate %}/\n\n/g;" \ +-pe "s/~~~/\`\`\`/g;" \ +-pe "s/([^\n\`])\n([^\n\`\|])(?=([^\`]|\`(?!\`))*((\`\`\`[^\`]+\`\`\`)([^\`]|\`(?!\`))*)*$)/\1 \2/g;" \ +-pe "s/(\n\n\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|?)\n(?!\| *-+ *\|)/\n\n\1\n|---|---|---|---|---|---|---|\n/g;" \ +-pe "s/(\n\n\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|?)\n(?!\| *-+ *\|)/\n\n\1\n|---|---|---|---|---|---|\n/g;" \ +-pe "s/(\n\n\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|?)\n(?!\| *-+ *\|)/\n\n\1\n|---|---|---|---|---|\n/g;" \ +-pe "s/(\n\n\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|?)\n(?!\| *-+ *\|)/\n\n\1\n|---|---|---|---|\n/g;" \ +-pe "s/(\n\n\|[^\|\n]+\|[^\|\n]+\|[^\|\n]+\|?)\n(?!\| *-+ *\|)/\n\n\1\n|---|---|---|\n/g;" \ +-pe "s/(\n\n\|[^\|\n]+\|[^\|\n]+\|?)\n(?!\| *-+ *\|)/\n\n\1\n|---|---|\n/g;" \ +-pe "s/\|[-]+(?=[\|\n])/| --- /g;" \ +-pe "s/\n\n+/\n\n/g;"