Last active
December 18, 2015 02:38
-
-
Save gchiu/5712068 to your computer and use it in GitHub Desktop.
convert embedded html tables to asciid doc format
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
REBOL [ | |
author: "Ingo Hohmann" | |
date: 2013-06-04 | |
purpose: "Change html tables to asciidoc format" | |
Version: 0.5 | |
] | |
ht2at: html-table-2asciidoc: funct [ input ] [ | |
output: copy #{} | |
space: #{20} | |
emit: func [text ] [ | |
if space <> text [ | |
append output text | |
] | |
] | |
remit: func [text [block!]] [ | |
emit reform text | |
] | |
text-rule: [ | |
copy text to "<" (emit text) | |
] | |
tag-rule: [ | |
"<" [ | |
; opening tags | |
["table" | |
here: | |
thru "</table>" | |
there: | |
(change/part here trim/lines copy/part here there there) | |
:here | |
; TODO: Add table setup | |
( | |
emit {[options="header"]^/|====^/} | |
) | |
thru ">" | |
] | |
| | |
["tr" | |
;(emit newline) | |
thru ">" (emit "|") | |
] | |
| | |
["td" thru ">" ] | |
| | |
["th" thru ">" ] | |
| | |
["tt" thru ">" ] | |
| | |
; closing tags | |
["/table" | |
(emit "|====^/") | |
thru ">" | |
] | |
| | |
["/td" | |
thru ">" | |
here: | |
[ | |
["</" :here] | |
| | |
[(emit "|")] | |
] | |
] | |
| | |
["/th" | |
thru ">" | |
here: | |
[ | |
["</" :here] | |
| | |
[(emit "|")] | |
] | |
] | |
| | |
["/tr" | |
(emit newline) | |
thru ">" | |
] | |
| | |
; catch all | |
["/" thru ">" ] | |
| | |
[thru ">"] | |
] | |
] | |
parse input [ | |
some [ | |
tag-rule | text-rule | |
] | |
] | |
either empty? output [ | |
input | |
][ | |
output | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Graphics