示例#1
0
    def extractMultilineParameter(self, text, startRow):
        endRow = startRow
        while endRow < len(text):
            # The end of a multi-line parameter
            # is marked by a line which is not all whitespace
            # and has no indentation.
            if (_leadingTabs(text[endRow],
                             globalOptions().tabSize)[0] == 0
                    and text[endRow].strip() != ''):
                break
            endRow += 1

        # However, we do not include those whitespace-lines _at the end_
        # that lack indentation. Excluding these lines is important;
        # otherwise a following header-line could be interpreted as
        # a paragraph followed by a separator-line, since there is no
        # separating whitespace. It is also important to preserve those
        # empty-lines which are indented; that whitespace may be significant
        # for a macro.
        while (endRow > startRow
               and _leadingTabs(text[endRow - 1],
                                globalOptions().tabSize)[0] == 0
               and text[endRow - 1].strip() == ''):
            endRow -= 1

        # Copy the parameter and remove the indentation from it.
        parameterSet = [
            _removeLeadingTabs(line,
                               globalOptions().tabSize, 1)
            for line in text[startRow:endRow]
        ]

        return parameterSet
示例#2
0
    def expand(self, parameter, remark):
        document = remark.document
        fileName = remark.documentTree.fullName(document)

        text = readFile(fileName, globalOptions().maxFileSize)

        return text
示例#3
0
def saveRemarkToHtml(remarkText,
                     document,
                     documentTree,
                     outputRootDirectory,
                     reporter=Reporter()):
    '''
    Converts Remark text to html text and saves it to a file.

    remarkText (list of strings):
    The Remark text to convert.

    documentTree (DocumentTree):
    The document-tree to use.

    outputRootDirectory (string):
    The output directory to save the file in.

    reporter (Reporter):
    The reporter to use for reporting.
    '''
    # Convert Remark to Markdown.
    markdownText, headText = convertRemarkToMarkdown(remarkText, document,
                                                     documentTree,
                                                     outputRootDirectory,
                                                     reporter)

    # Find out some names.
    outputRelativeName = outputDocumentName(document.relativeName)
    outputFullName = os.path.join(outputRootDirectory, outputRelativeName)

    if globalOptions().generateMarkdown:
        # Write the generated Markdown source.
        writeFile(markdownText,
                  withoutFileExtension(outputFullName) + '.md.txt')

    # Convert Markdown to Html.
    htmlText = convertMarkdownToHtml(markdownText, headText, document,
                                     documentTree, outputRootDirectory,
                                     reporter)

    # Write the generated html.
    writeFile(htmlText, outputFullName)
示例#4
0
    def expand(self, parameter, remark):
        document = remark.document
        reporter = remark.reporter
        
        # Find out the relative-name of the file
        # to be read.

        if len(parameter) == 0:
            # No file-paths were given.
            return []

        if len(parameter) > 1:
            reporter.reportWarning(
                ['Multiple file-paths given:'] + parameter + ['Using the first.'], 'invalid-input')

        searchName = parameter[0]

        # Search for the file in the document-tree.
        input, unique = remark.documentTree.findDocument(
            searchName, document.relativeDirectory)

        if not unique:
            # There are many matching image files with the given name.
            # Report a warning, pick one arbitrarily, and continue.
            remark.reporter.reportAmbiguousDocument(searchName)

        if input == None:
            # The file was not found. 
            remark.reporter.reportMissingDocument(searchName)
            return []

        # Form the absolute-path to the file.
        inputPath = os.path.join(remark.inputRootDirectory, input.relativeName)

        # Read the file.
        text = readFile(inputPath, globalOptions().maxFileSize)

        return text
示例#5
0
 def parseTags(self, fileName, reporter):
     return self.tagParser.parse(fileName,
                                 globalOptions().maxTagLines, reporter)