class Asciidoctor::Block
def htmlify(string)
htmlify(asciidoc_string)
asciidoc_string = "Make 'this'
Examples
string - The String source string in Asciidoc format.
Asciidoc characters converted and HTML entities escaped.
Private: Return a String HTML version of the source string, with
def htmlify(string) unless string.nil? html = string.dup # Convert reference links to "link:" asciidoc for later HTMLification. # This ensures that eg. "<<some reference>>" is turned into a link but # "`<<<<<` and `>>>>>` are conflict markers" is not. This is much # easier before the HTML is escaped and <> are turned into entities. html.gsub!( /(^|[^<])<<([^<>,]+)(,([^>]*))?>>/ ) { "#{$1}link:##{$2}[" + ($4.nil? ? document.references[$2] : $4).to_s + "]" } # Do the same with URLs html.gsub!( /(^|[^(`|link:)])(https?:\/\/[^\[ ]+)(\[+[^\]]*\]+)?/ ) do pre = $1 url = $2 link = ( $3 || $2 ).gsub( /(^\[|\]$)/,'' ) link = url if link.empty? "#{pre}link:#{url}[#{link}]" end html.gsub!(Asciidoctor::REGEXP[:biblio], '<a name="\1">[\1]</a>') html.gsub!(Asciidoctor::REGEXP[:ruler], "<hr>\n") html.gsub!(/``([^`']*)''/m, '“\1”') html.gsub!(/(?:\s|^)`([^`']*)'/m, '‘\1’') # TODO: This text thus quoted is supposed to be rendered as an # "inline literal passthrough", meaning that it is rendered # in a monospace font, but also doesn't go through any further # text substitution, except for special character substitution. # So we need to technically pull this text out, sha it and store # a marker and replace it after the other gsub!s are done in here. # See: http://www.methods.co.nz/asciidoc/userguide.html#X80 html.gsub!(/`([^`]+)`/m) { "<tt>#{$1.gsub( '*', '{asterisk}' ).gsub( '\'', '{apostrophe}' )}</tt>" } html.gsub!(/([\s\W])#(.+?)#([\s\W])/, '\1\2\3') # "Unconstrained" quotes html.gsub!(/\_\_([^\_]+)\_\_/m, '<em>\1</em>') html.gsub!(/\*\*([^\*]+)\*\*/m, '<strong>\1</strong>') html.gsub!(/\+\+([^\+]+)\+\+/m, '<tt>\1</tt>') html.gsub!(/\^\^([^\^]+)\^\^/m, '<sup>\1</sup>') html.gsub!(/\~\~([^\~]+)\~\~/m, '<sub>\1</sub>') # "Constrained" quotes, which must be bounded by white space or # common punctuation characters html.gsub!(/(^|\s|\W)\*([^\*]+)\*(\s|\W|$)/m, '\1<strong>\2</strong>\3') html.gsub!(/(^|\s|\W)'(.+?)'(\s|\W|$)/m, '\1<em>\2</em>\3') # restore escaped single quotes after processing emphasis html.gsub!(/(\w)\\'(\w)/, '\1\'\2') html.gsub!(/(^|\s|\W)_([^_]+)_(\s|\W|$)/m, '\1<em>\2</em>\3') html.gsub!(/(^|\s|\W)\+([^\+]+)\+(\s|\W|$)/m, '\1<tt>\2</tt>\3') html.gsub!(/(^|\s|\W)\^([^\^]+)\^(\s|\W|$)/m, '\1<sup>\2</sup>\3') html.gsub!(/(^|\s|\W)\~([^\~]+)\~(\s|\W|$)/m, '\1<sub>\2</sub>\3') html.gsub!(/\\([\{\}\-])/, '\1') html.gsub!(/linkgit:([^\]]+)\[(\d+)\]/, '<a href="\1.html">\1(\2)</a>') html.gsub!(/link:([^\[]+)(\[+[^\]]*\]+)/ ) { "<a href=\"#{$1}\">#{$2.gsub( /(^\[|\]$)/,'' )}</a>" } html.gsub!(Asciidoctor::REGEXP[:line_break], '\1<br/>') html end end