for the good of luna /hj
This commit is contained in:
commit
bd7c371876
3 changed files with 209 additions and 0 deletions
68
maam.rb
Executable file
68
maam.rb
Executable file
|
|
@ -0,0 +1,68 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
def dorun(args)
|
||||||
|
if args.length == 0
|
||||||
|
args = ['-']
|
||||||
|
end
|
||||||
|
files = []
|
||||||
|
args.each do |arg|
|
||||||
|
if arg == '--help'
|
||||||
|
dohelp;exit
|
||||||
|
elsif arg == '—help'
|
||||||
|
dohelp;exit
|
||||||
|
elsif arg == '-h'
|
||||||
|
dohelp;exit
|
||||||
|
end
|
||||||
|
files << arg
|
||||||
|
end
|
||||||
|
|
||||||
|
files.each do |filename|
|
||||||
|
if filename == '-'
|
||||||
|
puts convert(STDIN.read)
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
File.open(filename, 'r') do |f|
|
||||||
|
puts convert(f.read)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def dohelp
|
||||||
|
puts "Maam - Merry Anya's ANSI woMan page printer"
|
||||||
|
puts "Pass files to maam and get output of the files"
|
||||||
|
puts " using ansi escapes rather than itty escapes."
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert(file)
|
||||||
|
file = file.gsub( /\x11\[s(?<style>[0-9a-fA-F]{4})\]/ ) do
|
||||||
|
out = "\x1b["
|
||||||
|
hexes = $~[:style].chars.map { |char| char.hex }
|
||||||
|
if hexes[0] == 7
|
||||||
|
# nothing; this is itty's default foreground
|
||||||
|
elsif hexes[0] < 8
|
||||||
|
out += ";3#{hexes[0]}"
|
||||||
|
else
|
||||||
|
out += ";9#{hexes[0]-8}"
|
||||||
|
end
|
||||||
|
if hexes[1] == 0
|
||||||
|
# nothing; this is itty's default background
|
||||||
|
elsif hexes[1] < 8
|
||||||
|
out += ";4#{hexes[1]}"
|
||||||
|
else
|
||||||
|
out += ";10#{hexes[1]-8}"
|
||||||
|
end
|
||||||
|
out += (hexes[2] & 1 != 0) ? ";1" : "" # bold
|
||||||
|
out += (hexes[2] & 2 != 0) ? ";3" : "" # italic
|
||||||
|
out += (hexes[2] & 4 != 0) ? ";4" : "" # underline
|
||||||
|
out += (hexes[2] & 8 != 0) ? "" : "" # show/hide cursor (ignored)
|
||||||
|
out += 'm' # end of escape
|
||||||
|
|
||||||
|
next out #<< implicit return
|
||||||
|
end
|
||||||
|
file = file.gsub("\x11", "") # remove invalid escapes
|
||||||
|
file += "\x1b[m" # reset at the end
|
||||||
|
file
|
||||||
|
end
|
||||||
|
|
||||||
|
dorun ARGV
|
||||||
117
mdtw.rb
Executable file
117
mdtw.rb
Executable file
|
|
@ -0,0 +1,117 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
FMT = {
|
||||||
|
:re => "\x11[s7000]", # reset
|
||||||
|
:h1 => "\x11[sD050]", # [x] # heading 1
|
||||||
|
:h2 => "\x11[s5040]", # [x] ## heading 2
|
||||||
|
:h3 => "\x11[s4030]", # [x] ### heading 3
|
||||||
|
:h4 => "\x11[s4020]", # [x] #### heading 4
|
||||||
|
:em => "\x11[s7010]", # [x] **bold** __bold__
|
||||||
|
:it => "\x11[s7020]", # [x] *italic* _italic_
|
||||||
|
:bi => "\x11[s7030]", # [x] ___bold italic___ ***...***
|
||||||
|
:hi_it => "\x11[sA020]", # [x] _=highlighted italic=_ *=...=*
|
||||||
|
:hi => "\x11[sA000]", # [x] ==highlight==
|
||||||
|
:co => "\x11[sE800]", # [x] `code` ``...``
|
||||||
|
:un => "\x11[s2040]", # [x] ~~underline~~
|
||||||
|
:x => "\x11[sC000]", # [x] * list bullet
|
||||||
|
}
|
||||||
|
|
||||||
|
def dohelp
|
||||||
|
puts "MDTW - Markdown Trans Woman"
|
||||||
|
puts "Pass markdown files to MDTW and recieve output"
|
||||||
|
puts " of woman pages with itty escapes."
|
||||||
|
end
|
||||||
|
|
||||||
|
def dorun(args)
|
||||||
|
files = []
|
||||||
|
args.each do |arg|
|
||||||
|
if arg == '--help'
|
||||||
|
dohelp;exit
|
||||||
|
elsif arg == '—help'
|
||||||
|
dohelp;exit
|
||||||
|
elsif arg == '-h'
|
||||||
|
dohelp;exit
|
||||||
|
end
|
||||||
|
files << arg
|
||||||
|
end
|
||||||
|
|
||||||
|
files.each do |filename|
|
||||||
|
if filename == '-'
|
||||||
|
puts convert(STDIN.read)
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
File.open(filename, 'r') do |f|
|
||||||
|
puts convert(f.read)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert(file_input)
|
||||||
|
file_input.gsub!( /^\#{1} (?<text>.*)$/ ) do |match|
|
||||||
|
next "#{FMT[:h1]}#{$~[:text]}#{FMT[:re]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
file_input.gsub!( /^\#{2} (?<text>.*)$/ ) do |match|
|
||||||
|
next "#{FMT[:h2]}#{$~[:text]}#{FMT[:re]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
file_input.gsub!( /^\#{3} (?<text>.*)$/ ) do |match|
|
||||||
|
next "#{FMT[:h3]}#{$~[:text]}#{FMT[:re]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
file_input.gsub!( /^\#{4} (?<text>.*)$/ ) do |match|
|
||||||
|
next "#{FMT[:h4]}#{$~[:text]}#{FMT[:re]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
file_input.gsub!( /^(?<indent>[ \t]*)(?<aro>\>+)(?=[ \t].*$)/ ) do |match|
|
||||||
|
denter = "\t" * $~[:aro].length
|
||||||
|
next "#{$~[:indent]}#{denter}"
|
||||||
|
end
|
||||||
|
|
||||||
|
file_input.gsub!( /^(?<indent>[ \t]*)(?<x>([\-\*]|(?<num>[0-9]+)[\.\)]))(?= .*$)/ ) do |match|
|
||||||
|
ilevel = $~[:indent].each_char.reduce(0) do |sum,ch|
|
||||||
|
case ch
|
||||||
|
when ' ' then sum += 1
|
||||||
|
when '\t' then sum += 4
|
||||||
|
else sum
|
||||||
|
end
|
||||||
|
end
|
||||||
|
ilevel = ilevel / 4
|
||||||
|
|
||||||
|
bullet = $~[:x]
|
||||||
|
if bullet == '-' || bullet == '*'
|
||||||
|
bullet = ["\u2022", "\u25E6", "\u25AA"][ilevel % 3]
|
||||||
|
elsif $~[:num]
|
||||||
|
# do nothing, case here for conveinence
|
||||||
|
end
|
||||||
|
next "#{$~[:indent]}#{FMT[:x]}#{bullet}#{FMT[:re]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
file_input.gsub!( /^(?<it>[_\-\*])\k<it>{2}$/ ) do |match|
|
||||||
|
next $~[:it] * 20
|
||||||
|
end
|
||||||
|
file_input.gsub!( /~~(?<text>.+?)~~/ ) do |match|
|
||||||
|
next "#{FMT[:un]}#{$~[:text]}#{FMT[:re]}"
|
||||||
|
end
|
||||||
|
file_input.gsub!( /==(?<text>.+?)==/ ) do |match|
|
||||||
|
next "#{FMT[:hi]}#{$~[:text]}#{FMT[:re]}"
|
||||||
|
end
|
||||||
|
file_input.gsub!( /(?<it>[_\*])=(?<text>.+?)=\k<it>/ ) do |match|
|
||||||
|
next "#{FMT[:hi_it]}#{$~[:text]}#{FMT[:re]}"
|
||||||
|
end
|
||||||
|
file_input.gsub!( /(?<it>[_\*])(?<text>[^_\*]+?)\k<it>/ ) do |match|
|
||||||
|
next "#{FMT[:it]}#{$~[:text]}#{FMT[:re]}"
|
||||||
|
end
|
||||||
|
file_input.gsub!( /(?<it>[_\*])\k<it>(?<text>[^_\*]+?)\k<it>{2}/ ) do |match|
|
||||||
|
next "#{FMT[:em]}#{$~[:text]}#{FMT[:re]}"
|
||||||
|
end
|
||||||
|
file_input.gsub!( /(?<it>[_\*])\k<it>{2}(?<text>[^_\*]+?)\k<it>{3}/ ) do |match|
|
||||||
|
next "#{FMT[:bi]}#{$~[:text]}#{FMT[:re]}"
|
||||||
|
end
|
||||||
|
file_input.gsub!( /(?<it>``?)(?<text>[^`]+?)\k<it>/ ) do |match|
|
||||||
|
next "#{FMT[:co]}#{$~[:text]}#{FMT[:re]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
dorun ARGV
|
||||||
24
readme.md
Normal file
24
readme.md
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
# Anya's util**itty**s
|
||||||
|
|
||||||
|
Anya's utilities for itty.
|
||||||
|
|
||||||
|
## MDTW
|
||||||
|
|
||||||
|
MDTW or "Markdown Trans Woman" is a program that aims to convert Markdown files to Woman files.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ruby mdtw.rb mymarkdownfile.md > mywomanfile
|
||||||
|
```
|
||||||
|
|
||||||
|
## Maam
|
||||||
|
|
||||||
|
Maam or "Merry Anya's ANSI woMan page printer" is a utility for printing woman pages
|
||||||
|
to the console using ANSI escape sequences.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ruby maam.rb mywomanfile
|
||||||
|
```
|
||||||
Loading…
Add table
Add a link
Reference in a new issue