Skip to content

Instantly share code, notes, and snippets.

@sotolf2
Created May 25, 2022 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sotolf2/1b1410cfa6b86a9406228ee608992ba3 to your computer and use it in GitHub Desktop.
Save sotolf2/1b1410cfa6b86a9406228ee608992ba3 to your computer and use it in GitHub Desktop.
## 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