示例#1
0
    def expand(self, parameter, remark):
        scope = remark.scopeStack.top()
        className = scope.getString('ParentList.class_name', 'ParentList')

        # Gather document's parents one by one.
        parentSet = []
        document = remark.document
        while document != document.parent:
            parentSet.append(document)
            document = document.parent

        # Report the parents in reverse order
        # (the root document first).
        level = 1
        text = []
        for i in reversed(range(0, len(parentSet))):
            document = parentSet[i]
            linkText = remark.remarkLink(document.linkDescription(),
                                         remark.document, document)

            # Strictly speaking, Markdown does not
            # use the actual numbers, so we could
            # as well set them all to 1. However,
            # the numbers might be useful for debugging
            # the intermediate output later on.
            text.append(repr(level) + '. ' + linkText)
            level += 1

        return markdownRegion(remark.convert(text), {'class': className})
示例#2
0
    def expand(self, parameter, remark):
        scope = remark.scopeStack.top()

        className = scope.getString('Verbatim.class_name', 'Verbatim')

        text = []
        for line in parameter:
            text.append('\t' + line)

        return markdownRegion(text, {'class': className})
示例#3
0
    def expand(self, parameter, remark):
        # Precomputation
        self.remark = remark
        self.document = remark.document
        self.documentTree = remark.documentTree
        scope = remark.scopeStack.top()

        # Variables
        self.minDepth = scope.getInteger('DocumentTree.min_depth', 1)
        self.maxDepth = scope.getInteger('DocumentTree.max_depth', 10)
        self.rootName = scope.getString('DocumentTree.root_document', self.document.fileName)
        self.className = scope.getString('DocumentTree.class_name', 'DocumentTree')
        self.includeGlob = scope.get('DocumentTree.include', ['file_name *'])
        self.includeRegex = scope.get('DocumentTree.include_regex')
        self.excludeGlob = scope.get('DocumentTree.exclude')
        self.excludeRegex = scope.get('DocumentTree.exclude_regex')
        self.compact = scope.getInteger('DocumentTree.compact', 1)

        self.includeMap = {}
        self._parse(self.includeGlob, self.includeMap, globToRegex)
        self._parse(self.includeRegex, self.includeMap, lambda x: x + r'\Z')

        self.includeFilter = {}
        for tagName, regex in self.includeMap.items():
            self.includeFilter[tagName] = re.compile(combineRegex(regex))

        self.excludeMap = {}
        self._parse(self.excludeGlob, self.excludeMap, globToRegex)
        self._parse(self.excludeRegex, self.excludeMap, lambda x: x + r'\Z')

        self.excludeFilter = {}
        for tagName, regex in self.excludeMap.items():
            self.excludeFilter[tagName] = re.compile(combineRegex(regex))

        rootDocument, unique = self.documentTree.findDocument(self.rootName, 
                                                      self.document.relativeDirectory)
        if rootDocument == None:
            self.remark.reporter.reportMissingDocument(self.rootName)
            return []
        
        if not unique:
            self.remark.reporter.reportAmbiguousDocument(self.rootName)
            
        # Start reporting the document-tree using the
        # given root document.
        self.visitedSet = set()
        text = ['']
        self._workDocument(rootDocument, text, 0)

        if text == ['']:
            return []

        return markdownRegion(
            remark.convert(text), 
            {'class' : self.className})
示例#4
0
    def expand(self, parameter, remark):
        scope = remark.scopeStack.top()

        className = scope.getString('Example.class_name', 'Example')

        text = remark.macro('Verbatim', parameter)
        text.append('')

        text += markdownRegion(remark.convert(parameter), {'class': className})

        return text
示例#5
0
    def expand(self, parameter, remark):
        document = remark.document
        documentTree = remark.documentTree
        scope = remark.scopeStack.top()

        # Variables
        className = scope.getString('Index.class_name', 'Index')

        fullPath = os.path.join(documentTree.rootDirectory,
                                document.relativeDirectory)
        entrySet = ['..'] + listDirectory(fullPath)

        # Gather the files and directories in the
        # document's directory.
        fileSet = []
        directorySet = []
        for entry in entrySet:
            relativeName = os.path.join(document.relativeDirectory, entry)
            fullName = os.path.join(documentTree.rootDirectory, relativeName)
            relativeName = unixDirectoryName(relativeName)
            if os.path.isdir(fullName):
                if relativeName in documentTree.directorySet:
                    directorySet.append(entry)
            elif documentTree.findDocumentByRelativeName(relativeName):
                fileSet.append(entry)

        # Create links for the directories.
        text = []
        for directory in directorySet:
            linkDirectory = os.path.join(document.relativeDirectory, directory)
            directoryIndexName = 'directory.remark-index'
            directoryDocument = documentTree.findDocumentLocal(
                directoryIndexName, linkDirectory)
            assert directoryDocument != None

            text.append(' 1. ' + remark.remarkLink(
                escapeMarkdown(directory + '/'), document, directoryDocument))

        # Create links for the files.
        for fileName in fileSet:
            fileDocument = documentTree.findDocumentLocal(
                fileName, document.relativeDirectory)
            assert fileDocument != None

            text.append(' 1. ' + remark.remarkLink(escapeMarkdown(fileName),
                                                   document, fileDocument))

        text.append('')

        return markdownRegion(remark.convert(text), {'class': className})
示例#6
0
    def expand(self, parameter, remark):
        text = []

        # Variables
        scope = remark.scopeStack.top()
        className = scope.getString('EquationSet.class_name', 'EquationSet')

        for line in parameter:
            cleanLine = line.strip()
            if cleanLine != '':
                # An ordered list of equations.
                equationText = remark.macro(self.wrapMacro, [cleanLine])
                if len(equationText) > 0:
                    equationText[0] = '1. ' + equationText[0]
                text += equationText

        text =  markdownRegion(text, {'class' : className})

        return text
示例#7
0
    def expand(self, parameter, remark):
        document = remark.document
        documentTree = remark.documentTree
        scope = remark.scopeStack.top()

        # Variables
        self.rootName = scope.getString('SourceChildren.root_document',
                                        document.fileName)
        self.className = scope.getString('SourceChildren.class_name',
                                         'SourceChildren')
        self.title = scope.getString('SourceChildren.title', 'Files')

        text = []

        def prefixOf(left, right):
            return str.find(withoutFileExtension(right),
                            withoutFileExtension(left)) == 0

        def same(left, right):
            return withoutFileExtension(left) == withoutFileExtension(right)

        # Gather the list of source files.

        sortedMap = [
            x for x in document.childSet.values()
            if (x.tagString('document_type') == 'CppCodeView'
                or x.tagString('document_type') == 'CodeView')
        ]

        if len(sortedMap) == 0:
            # There are no source files.
            return text

        # Sort the list alphabetically w.r.t. the relative file names.

        sortedMap.sort(key=lambda x: x.relativeName)

        # Given an alphabetically sorted list of source files,
        # group all files that have the same name without
        # extension. The group shares the same description.

        outputDirectory = document.relativeDirectory
        beginIndex = 0
        groupSet = []
        description = ''
        detail = ''
        for i in range(0, len(sortedMap)):
            sourceDocument = sortedMap[i]
            reference = sortedMap[beginIndex]

            # Note that it is really the _description_ we want to
            # use here, rather than the link description.
            desc = sourceDocument.tagString('description')
            if desc != '':
                # If there are multiple descriptions, one is chosen
                # arbitrarily and a warning is emitted.
                if description != '':
                    message = [
                        'Multiple descriptions for a document-group.',
                        'Current: ' + description, 'New: ' + desc
                    ]
                    remark.reportWarning(message, 'ambiguous-input')
                description = desc

            det = sourceDocument.tagString('detail')
            if det != '':
                # If there are multiple details, one is chosen
                # arbitrarily and a warning is emitted.
                if detail != '':
                    message = [
                        'Multiple details for a document-group. ',
                        'Current: ' + detail, 'New: ' + det
                    ]
                    remark.reportWarning(message, 'ambiguous-input')
                detail = det

            if i == len(sortedMap) - 1 or not same(
                    sortedMap[i + 1].relativeName, reference.relativeName):
                groupSet.append(
                    [description, detail, sortedMap[beginIndex:i + 1]])
                beginIndex = i + 1
                description = ''
                detail = ''

        # If a group does not have a description, it can be
        # joined together with a preceding described group, on the condition
        # that without extensions the names in the preceding group are
        # prefixes of the names in the following group.
        i = 1
        while i < len(groupSet):
            joined = False
            for j in range(i - 1, -1, -1):
                if groupSet[i][0] == '' and prefixOf(
                        groupSet[j][2][0].relativeName,
                        groupSet[i][2][0].relativeName):
                    #print('Join', groupSet[j][2][0].relativeName, groupSet[i][2][0].relativeName)
                    groupSet[j][2] += groupSet[i][2]
                    groupSet[i:i + 1] = []
                    joined = True
                    break
            if not joined:
                i += 1

        # Set default descriptions for those
        # groups that do not have a description.
        for group in groupSet:
            if group[0] == '':
                message = ['Description missing for the document-group']
                for child in group[2]:
                    message.append(child.fileName)
                remark.reportWarning(message, 'missing-description')

        # Find the first group that has no description.
        i = 0
        while i < len(groupSet):
            if groupSet[i][0] == '':
                break
            i += 1

        # Join all groups without a description to the
        # first such group.
        if i < len(groupSet):
            j = i + 1
            while j < len(groupSet):
                if groupSet[j][0] == '':
                    groupSet[i][2] += groupSet[j][2]
                    groupSet[j:j + 1] = []
                else:
                    j += 1

        # Output the groups
        #for group in groupSet:
        #    for child in group[2]:
        #        print(child.relativeName)
        #    print('')

        # Order the groups in alphabetical order w.r.t.
        # their descriptions.
        groupSet.sort(key=lambda x: x[0])

        # Move the unnamed group to the end.
        if len(groupSet) > 0 and groupSet[0][0] == '':
            groupSet.append(groupSet[0])
            groupSet[0:1] = []

        defaultDescription = '?'

        # Output the links in the groups together
        # with a description for the group.

        # The title is output only if its non-empty.
        if len(self.title.strip()) > 0:
            # Output the title
            text.append('')
            text.append(self.title)
            text.append('---')

        text.append('')
        for group in groupSet:
            # Output description for the group.
            description = group[0]
            if description == '':
                description = defaultDescription

            text.append('')
            text.append('### ' + description)
            text.append('')

            # Output detailed description for the group
            # if it's present.
            detail = group[1]
            if detail != '':
                text.append('')
                text.append('_' + detail + '_')
                text.append('')

            # Output the links in the group as a list.
            for child in group[2]:
                text.append('* ' + remark.remarkLink(
                    escapeMarkdown(child.fileName), document, child))

        return markdownRegion(remark.convert(text), {'class': self.className})