Last active
August 19, 2016 15:22
-
-
Save ochaochaocha3/308787cc1b905e90fc4b8daef6bc0b36 to your computer and use it in GitHub Desktop.
MobileFrontend configuration options extraction and conversion to MediaWiki markup
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
source = File.read('README.md') | |
m = source.match(/^Configuration options\n---------------------/) | |
raise 'Missing "Configuration options" headng' unless m | |
body = m.post_match.strip | |
# Adjust heading level | |
body.gsub!(/^##/, '') | |
# Markdown to MediaWiki conversion with pandoc | |
pandoc_output = IO.popen('pandoc -f markdown -t mediawiki', 'r+') { |io| | |
io.print(body) | |
io.close_write | |
io.read | |
} | |
lines = pandoc_output. | |
strip. | |
lines. | |
map(&:chomp) | |
in_source_code = false | |
modified_lines = lines.map { |line| | |
if in_source_code | |
in_source_code = false if line.include?('</source>') | |
next line | |
end | |
if line.start_with?('<source ') | |
in_source_code = true | |
next line | |
end | |
next line unless /\A\w/ === line | |
"<translate>#{line}</translate>" | |
} | |
puts(modified_lines) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment