Last active
August 29, 2015 14:27
-
-
Save alepore/b0b28846c46da681dd6e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Sablon | |
module Redcarpet | |
module Render | |
class ImprovedWordML < WordML | |
LIST_PATTERN = <<-XML.gsub("\n", "") | |
<w:p> | |
<w:pPr> | |
<w:pStyle w:val="%s" /> | |
<w:numPr> | |
<w:ilvl w:val="%s"/> | |
<w:numId w:val="%s"/> | |
</w:numPr> | |
</w:pPr> | |
%s | |
</w:p> | |
XML | |
def list_item(content, list_type) | |
list_style = LIST_STYLE_MAPPING[list_type] | |
indentation_level = 0 | |
# add correct indentation information reading our special pattern | |
content.gsub!(/#####(\d)#####/) do |match| | |
indentation_level = $1.to_i | |
'' | |
end | |
LIST_PATTERN % [list_style, indentation_level, 1, content] | |
end | |
def preprocess(full_document) | |
# remove blank spaces at the beginning of lists and save indentation info with a special pattern | |
# redcarpet will treat all items as level 0 list items, which is required to work with WordML | |
# and we will add correct indentation information later on list_item() | |
full_document.gsub(/^( +)- /) do |_| | |
"- ######{$1.size}#####" | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment