Commit 89a66d76 authored by Jonathan Corbet's avatar Jonathan Corbet Committed by Jani Nikula

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.

[Jani: Change usage to tmplcvt <in> <out>. Fix escaping for docproc
directives. Add support the new kernel-doc extension.]
Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
Signed-off-by: default avatarJani Nikula <jani.nikula@intel.com>
parent c13ce448
#
# 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
#
# Wrap docproc directives in para and code blocks.
#
s%^\(!.*\)$%<para><code>DOCPROC: \1</code></para>%
#
# 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
#
# Unwrap docproc directives.
#
s/^``DOCPROC: !E\(.*\)``$/.. kernel-doc:: \1\n :export:/
s/^``DOCPROC: !I\(.*\)``$/.. kernel-doc:: \1\n :internal:/
s/^``DOCPROC: !F\([^ ]*\) \(.*\)``$/.. kernel-doc:: \1\n :functions: \2/
s/^``DOCPROC: !P\([^ ]*\) \(.*\)``$/.. kernel-doc:: \1\n :doc: \2/
s/^``DOCPROC: \(!.*\)``$/.. WARNING: DOCPROC directive not supported: \1/
#
# Trim trailing whitespace.
#
s/[[:space:]]*$//
#!/bin/bash
#
# Convert a template file into something like RST
#
# fix <function>
# feed to pandoc
# fix \_
# title line?
#
in=$1
rst=$2
tmp=$rst.tmp
cp $in $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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment