lang/python/ SimpleMarkdownHelper
Example usage:
cat file | md q
pp | md q # pp is a command I have which pastes from the clipboard on cygwin, macos and x11.
takes a text file (or from the clipboard) adds leading >
to it and prints it out.
There is also the w command which textwraps.
Source
#!/usr/bin/env python3
import sys
def main():
args = sys.argv[1:]
md = sys.stdin.read()
for arg in args:
if arg in actions:
md = actions[arg](md)
print(md)
def blockquote(md):
a = []
for x in md.splitlines():
a.append(f"> {x}")
return "\n".join(a)
import textwrap
def wrap(md):
t = textwrap.wrap(md)
return "\n".join(t)
actions = {}
actions['blockquote'] = blockquote
actions['q'] = blockquote
actions['w'] = wrap
if __name__ == "__main__":
main()