Skip to content

Instantly share code, notes, and snippets.

@ochaochaocha3
Last active August 19, 2016 15:22
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 ochaochaocha3/308787cc1b905e90fc4b8daef6bc0b36 to your computer and use it in GitHub Desktop.
Save ochaochaocha3/308787cc1b905e90fc4b8daef6bc0b36 to your computer and use it in GitHub Desktop.
MobileFrontend configuration options extraction and conversion to MediaWiki markup
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