doc: Fix the rendering of double quotes and semicolons

CMake uses quotes and semicolon in its internal list datatype.

Previously, all double quotes were converted to single quotes to
avoid this problem. Semicolors were interpreted as newlines in
ldoc.

With this commit, both of them render fine. This was required
because a new example uses CSS and XML where those symbols have
a specific meanning.
This commit is contained in:
Emmanuel Lepage Vallee 2021-09-11 18:59:46 -07:00
parent ddccddb6dc
commit 883cdb7f41
2 changed files with 10 additions and 7 deletions

View File

@ -38,7 +38,8 @@
# local use_li = ldoc.use_li
# local display_name = ldoc.display_name
# local iter = ldoc.modules.iter
# local function M(txt,item) return ldoc.markup(txt,item,ldoc.plain) end
# local function un_cmake(s) return s:gsub("&#59", ";"):gsub("&#34", '"') end
# local function M(txt,item) return ldoc.markup(txt and un_cmake(txt) or nil,item,ldoc.plain) end
# local nowrap = ldoc.wrap and '' or 'nowrap'
# local html_space = function(s) return s:gsub(" ", "%%20") end
# local no_underscores = function(s) return s:gsub("_", " ") end
@ -189,7 +190,7 @@
<h3>Usage:</h3>
<ul>
# for usage in iter(module.usage) do
$(li)<pre class="example">$(ldoc.escape(usage))</pre>$(il)
$(li)<pre class="example">$(ldoc.escape(un_cmake(usage)))</pre>$(il)
# end -- for
</ul>
# end -- if usage
@ -331,7 +332,7 @@
# end
# if kitem.usage then
<h3>Usage:</h3>
<pre class="example">$(ldoc.prettify(kitem.usage[1]))</pre>
<pre class="example">$(ldoc.prettify(un_cmake(kitem.usage[1])))</pre>
# end
# end
# if not kind:match("^ldoc_skip") then
@ -450,7 +451,7 @@
<h3>Usage:</h3>
<ul>
# for usage in iter(item.usage) do
$(li)<pre class="example">$(ldoc.prettify(usage))</pre>$(il)
$(li)<pre class="example">$(ldoc.prettify(un_cmake(usage)))</pre>$(il)
# end -- for
</ul>
# end -- if usage

View File

@ -85,7 +85,9 @@ function(escape_string variable content escaped_content line_prefix)
if(variable MATCHES "--DOC_HIDE_ALL")
return()
endif()
string(REGEX REPLACE "\n" ";" var_lines "${variable}")
string(REGEX REPLACE ";" "&#59" var_lines "${variable}")
string(REGEX REPLACE "\n" ";" var_lines "${var_lines}")
set(tmp_output ${content})
set(section OFF)
@ -101,7 +103,7 @@ function(escape_string variable content escaped_content line_prefix)
# Pick lines that are not specified to be hidden
if((NOT LINE MATCHES "^.*--DOC_[A-Z]+") AND (NOT section))
set(tmp_output ${tmp_output}\n${DOC_LINE_PREFIX}${line_prefix}${LINE})
set(tmp_output "${tmp_output}\n${DOC_LINE_PREFIX}${line_prefix}${LINE}")
endif()
# If we found a start marker previously, look for an end marker.
@ -347,7 +349,7 @@ foreach(file ${test_files})
# variable during the pre-processing.
# While at it, replace \" created by CMake by ',
# &quot; wont work in <code>.
string(REPLACE "\"" "'" ${TEST_NAME} ${ESCAPED_CODE_EXAMPLE})
string(REPLACE "\"" "&#34" ${TEST_NAME} ${ESCAPED_CODE_EXAMPLE})
endif()
endforeach()