Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
docs: (Sphinx) fixing limitation code
Also cleanup of latex-scan.py.
  • Loading branch information
joergsteffens committed Feb 28, 2019
1 parent cd2ced3 commit f39eb38
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 42 deletions.
24 changes: 16 additions & 8 deletions docs/manuals/en/new_main_reference/latex-scan.py
Expand Up @@ -5,11 +5,7 @@
from __future__ import print_function
import argparse
import logging
#import fileinput
from pandocfilters import toJSONFilter, Code, Str, Para, Plain
#from pyparsing import Word, alphas, alphanums, Literal, restOfLine, OneOrMore, \
# empty, Suppress, replaceWith, nestedExpr
from pyparsing import *
import re
import sys

Expand Down Expand Up @@ -938,11 +934,23 @@ def limitation(item):
# \index[general]{#1!Limitation!#2}%
# }
component, summary, text = item.getParameters()
if item.getOptionalParameters():
#item.replace(b':index:`{0}: {1}. <triple: Limitation; {0}; {1}>`\n{2}\n'.format(component, summary, text))
item.replace(b':index:`{0}: {1}. <triple: Limitation; {0}; {1}>`\n\n.. limitation:: **{1}.**\n{2}\n\n'.format(component, summary, text))

indenttext = ' '
# get indention of 2. line
match = re.match(r'.*?\n(\s*).*', text)
if match:
indenttext = match.expand(r'\1')
else:
item.replace(b':index:`{0}: {1}. <triple: Limitation; {0}; {1}>`\n\n.. limitation:: **Limitation {0}: {1}.**\n{2}\n\n'.format(component, summary, text))
# only a single line
match = re.match(r'(\s*).*', text)
if match:
indenttext = match.expand(r'\1')

#if item.getOptionalParameters():
# #item.replace(b':index:`{0}: {1}. <triple: Limitation; {0}; {1}>`\n{2}\n'.format(component, summary, text))
# item.replace(b':index:`{0}: {1}. <triple: Limitation; {0}; {1}>`\n\n.. limitation:: **{1}.**\n{2}\n\n'.format(component, summary, text))
#else:
item.replace(b'.. limitation:: {component}: {summary}.\n\n{indent}.. index::\n{indent} triple: Limitation; {component}; {summary}\n\n{text}\n\n'.format(indent=indenttext, component=component, summary=summary, text=text))



Expand Down
52 changes: 18 additions & 34 deletions docs/manuals/en/new_main_reference/source/extensions/limitation.py 100755 → 100644
@@ -1,53 +1,37 @@
# -*- coding: utf-8 -*-

from docutils import nodes
from docutils.parsers.rst import Directive
from docutils.parsers.rst import directives
#from sphinx.util.docutils import SphinxDirective

class Limitation(nodes.Structural, nodes.Element):
pass

class LimitationDirective(Directive):
class Limitation(Directive):

# Define the parameters the directive expects
required_arguments = 0
required_arguments = 1
optional_arguments = 0

# A boolean, indicating if the final argument may contain whitespace
final_argument_whitespace = True
option_spec = {'title', }
#option_spec = {'title', }
has_content = True

def run(self):
# Raise an error if the directive does not have contents.
sett = self.state.document.settings
env = self.state.document.settings.env

config = env.config

# Raise an error if the directive does not have contents.
self.assert_has_content()
text = '\n'.join(self.content)

# Get access to the options of directive
options = self.options

# Create the limitation content, to be populated by `nested_parse`.
limitation_content = nodes.paragraph(rawsource=text)

# Parse the directive contents.
self.state.nested_parse(self.content, self.content_offset, limitation_content)

# Create a title
limitation_title = nodes.title("Limitations: " + options["title"])

# Create the limitation node
node = Limitation()
node += limitation_title
node += limitation_content
title = 'Limitation: ' + self.arguments[0]
text = '\n'.join(self.content)

# Return the result
return [node]
paragraph = nodes.paragraph()
self.state.nested_parse(self.content, self.content_offset, paragraph)

#class Limitation(LimitationDirective):
# pass
result = nodes.section(ids=['limitation'])
result += nodes.title(text=title)
#result += nodes.paragraph(text=text)
result += paragraph
return [result]

def setup(app):
app.add_node(Limitation)
app.add_directive("limitation", LimitationDirective)
directives.register_directive("limitation", Limitation)

0 comments on commit f39eb38

Please sign in to comment.