Created
May 25, 2022 08:19
-
-
Save sotolf2/1b1410cfa6b86a9406228ee608992ba3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## A very silly little example to create bionic reading html documents | |
## from a text document. | |
## needs the markdown-package from nimble: | |
## | |
## $ nimble install markdown | |
## | |
import | |
markdown, | |
std/os, | |
std/strutils | |
proc printUsage() = | |
echo "Usage" | |
echo "=====" | |
echo "bionic [filename]" | |
echo "echos bionic html generated from the input text" | |
proc bionify(text: string): string = | |
for word in text.split(): | |
if word.len == 0: | |
continue | |
if word.len == 1: | |
result &= "**" | |
result &= word | |
result &= "** " | |
continue | |
let half = word.len div 2 | |
result &= "**" | |
result &= word[0..half - 1] | |
result &= "**" | |
result &= word[half..word.len - 1] | |
result &= " " | |
if paramCount() != 1: | |
printUsage() | |
let filename = paramStr(1) | |
let filedata = readFile(filename) | |
let mdText = bionify(filedata) | |
let html = markdown(mdText) | |
let oFileName = filename.split('.')[0] & ".html" | |
writeFile(oFileName, html) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment