diff options
author | Jonathan Corbet <corbet@lwn.net> | 2016-03-06 20:29:31 -0700 |
---|---|---|
committer | Jonathan Corbet <corbet@lwn.net> | 2016-03-06 20:29:31 -0700 |
commit | e42857499a97c417f47ac0a47360e081f9a4baac (patch) | |
tree | 508c7aa3393b9459cdf12f8deaea94b6dc858bcf | |
parent | 075035b0493ba16afce5f0734410ac0a1c87ab25 (diff) | |
download | lwn-e42857499a97c417f47ac0a47360e081f9a4baac.tar.gz lwn-e42857499a97c417f47ac0a47360e081f9a4baac.zip |
sphinx: cheesy script to convert .tmpl files
This script uses pandoc to convert existing DocBook template files to RST
templates. A couple of sed scripts are need to massage things both before
and after the conversion, but the result is then usable with no hand
editing.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
-rw-r--r-- | Documentation/sphinx/convert_template.sed | 15 | ||||
-rw-r--r-- | Documentation/sphinx/post_convert.sed | 7 | ||||
-rw-r--r-- | Documentation/sphinx/tmplcvt | 16 |
3 files changed, 38 insertions, 0 deletions
diff --git a/Documentation/sphinx/convert_template.sed b/Documentation/sphinx/convert_template.sed new file mode 100644 index 000000000000..fbf3b2828544 --- /dev/null +++ b/Documentation/sphinx/convert_template.sed @@ -0,0 +1,15 @@ +# +# Pandoc doesn't grok <function> or <structname>, so convert them +# ahead of time. +# +# Use "$bq" instead of "`" so that pandoc won't mess with it. +# +s%<function>\([^<(]\+\)()</function>%:c:func:$bq\1$bq%g +s%<function>\([^<(]\+\)</function>%:c:func:$bq\1$bq%g +s%<structname>struct *\([^<]\+\)</structname>%:ref:$bqstruct \1$bq%g +s%<structname>\([^<]\+\)</structname>%:ref:$bqstruct \1$bq%g +# +# If we put paragraph markers between docproc directives hopefully pandoc +# won't mess with them. +# +s%^\(!.*\)$%<para>\1</para>% diff --git a/Documentation/sphinx/post_convert.sed b/Documentation/sphinx/post_convert.sed new file mode 100644 index 000000000000..d5443ad5be74 --- /dev/null +++ b/Documentation/sphinx/post_convert.sed @@ -0,0 +1,7 @@ +# +# pandoc thinks that both "_" needs to be escaped. Remove the extra +# backslashes. Also put in proper backquotes now that pandoc won't quote +# them. +# +s/$bq/`/g +s/\\_/_/g diff --git a/Documentation/sphinx/tmplcvt b/Documentation/sphinx/tmplcvt new file mode 100644 index 000000000000..b3b85f67497b --- /dev/null +++ b/Documentation/sphinx/tmplcvt @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Convert a template file into something like RST +# +# fix <function> +# feed to pandoc +# fix \_ +# title line? +# +tmp=${1/tmpl/rst_tmp} +rst=${1/tmpl/rtmpl} +cp ../DocBook/$1 $tmp +sed --in-place -f convert_template.sed $tmp +pandoc -s -S -f docbook -t rst -o $rst $tmp +sed --in-place -f post_convert.sed $rst +rm $tmp |