Add CLI docs build tools

This commit is contained in:
kasper 2018-03-30 11:44:55 -04:00
parent f72e6926ca
commit 2e9c0b7b06
2 changed files with 96 additions and 0 deletions

View file

@ -0,0 +1,54 @@
#!/usr/bin/env python
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
import copy
from pandocfilters import toJSONFilters, Para, Str, Header, Space, Link
def remove_includes(key, value, format, meta):
if key == 'Para' and value[0]['c'] == '[!INCLUDE':
return Para([Str("")])
return None
def promote_and_capitalize_sections(key, value, format, meta):
if key == 'Header':
header_contents = value[2]
header_text = ' '.join([ x['c'] for x in header_contents if x['t'] == 'Str']).lower()
if header_text in ['name', 'synopsis', 'description', 'options', 'examples', 'environment variables']:
# capitalize
for element in header_contents:
if element['t'] == 'Str':
element['c'] = element['c'].upper()
# promote
value = Header(1, value[1], header_contents)
return value
return None
def demote_net_core_1_2(key, value, format, meta):
if key == 'Header':
header_id = value[1][0]
if header_id.startswith('net-core-'):
value = Header(2, value[1], value[2][0]['c'][1])
return value
return None
def remove_references(key, value, format, meta):
if key == 'Link':
pass
if value[1][0]['t'] == 'Code':
return value[1][0]
return Str(' '.join([e['c'] for e in value[1] if 'c' in e.keys()]))
return None
def main():
toJSONFilters([
remove_includes,
promote_and_capitalize_sections,
demote_net_core_1_2,
remove_references,
])
if __name__ == '__main__':
main()

View file

@ -0,0 +1,42 @@
#!/usr/bin/env sh
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
MANPAGE_TOOL_DIR=$(cd $(dirname $0); pwd)
cd $MANPAGE_TOOL_DIR/sdk
pandocVersion=2.1.3
pandocVersionedName=pandoc-$pandocVersion-1-amd64
if [ ! -x "$(command -v pandoc)" ]; then
echo "pandoc $pandocVersion not found, installing"
wget -q https://github.com/jgm/pandoc/releases/download/$pandocVersion/$pandocVersionedName.deb > /dev/null
apt install libgmp10 -y
dpkg -i $pandocVersionedName.deb
rm $pandocVersionedName.deb*
fi
if ! $(python -c "import pandocfilters" &> /dev/null); then
echo "pandocfilters package for python not found, installing v1.4.2"
wget -q https://github.com/jgm/pandocfilters/archive/1.4.2.zip -O pandocfilters-1.4.2.zip > /dev/null
unzip -o pandocfilters-1.4.2.zip > /dev/null
cd pandocfilters-1.4.2
python setup.py install
cd ..
rm -rf pandocfilters-1.4.2*
fi
echo "Downloading dotnet/docs master"
wget -q https://github.com/dotnet/docs/archive/master.zip > /dev/null
unzip -o master.zip > /dev/null
rm master.zip*
ls docs-master/docs/core/tools/dotnet*.md | while read -r line;
do
echo "Working on $line"
pandoc -s -t man -V section=1 -V header=".NET Core" --column=500 --filter $MANPAGE_TOOL_DIR/man-pandoc-filter.py "$line" -o "$(basename ${line%.md}.1)"
done
rm -rf docs-master