Пример #1
0
# -*- coding: utf-8 -*-

# Description: Copy macro
# Detail: Copies the input to output.

from Remark.Macro_Registry import registerMacro


class Copy_Macro(object):
    def name(self):
        return 'Copy'

    def expand(self, parameter, remark):
        text = parameter
        return text

    def expandOutput(self):
        return True

    def htmlHead(self, remark):
        return []

    def postConversion(self, remark):
        None


registerMacro('Copy', Copy_Macro())
Пример #2
0
            # Try to guess the type of the code.
            try:
                lexer = guess_lexer(inputText)
            except:
                remark.reporter.reportWarning(
                    'The code-type cannot be guessed from the content by Pygments. ' + 
                    'Setting code-type to text.', 'invalid-input')
                lexer = get_lexer_by_name('text')
        
        # Highlight the code.
        hilightedText = highlight(inputText, lexer, HtmlFormatter())

        # Prepare for Remark output.
        hilightedText = hilightedText.split('\n')

        return htmlRegion(hilightedText)

    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []                

    def postConversion(self, remark):
        None

registerMacro('Code', Code_Macro())
registerMacro('GenericCode', Code_Macro())


Пример #3
0
# -*- coding: utf-8 -*-

# Description: Html macro
# Detail: Copies the input to output and treats it as html.

from Remark.Macro_Registry import registerMacro
from Remark.FileSystem import htmlRegion


class Html_Macro(object):
    def name(self):
        return 'Html'

    def expand(self, parameter, remark):
        return htmlRegion(parameter)

    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []

    def postConversion(self, remark):
        None


registerMacro('Html', Html_Macro())
Пример #4
0
            linkDocument, unique = documentTree.findDocument(
                linkFileName, document.relativeDirectory)

            if not unique:
                remark.reporter.reportAmbiguousDocument(linkFileName)

            if linkDocument == None:
                remark.reporter.reportMissingDocument(linkFileName)
                continue

            text.append(
                remark.remarkLink(linkDocument.linkDescription(), document,
                                  linkDocument))

            if len(parameter) > 1:
                text.append('')

        return text

    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []

    def postConversion(self, remark):
        None


registerMacro('Link', Link_Macro())
Пример #5
0
        treeText = remark.macro('DocumentTree')

        text = []
        # Only create the title if at least
        # one link was produced.
        if (treeText != ['']):

            # Create the title.
            text.append('')
            if (self.title != ''):
                text.append(self.title)
                text.append('---')
                text.append('')

            # Append the links.
            text += treeText

        return text

    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []

    def postConversion(self, remark):
        None


registerMacro('DocChildren', DocChildren_Macro())
Пример #6
0
# -*- coding: utf-8 -*-

# Description: Comment macro
# Detail: Consumes its input and produces no output.

from Remark.Macro_Registry import registerMacro


class Comment_Macro(object):
    def name(self):
        return 'Comment'

    def expand(self, parameter, remark):
        # This macro simply eats its parameter. This allows
        # for commenting.
        text = []
        return text

    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []

    def postConversion(self, remark):
        None


registerMacro('Comment', Comment_Macro())
Пример #7
0
            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
    
    def expandOutput(self):
        return True
    
    def htmlHead(self, remark):
        return []                

    def postConversion(self, remark):
        None

registerMacro('ReadFile', ReadFile_Macro())
Пример #8
0
        #    oneLineRegexStr + r'|' +
        #    multiLineRegexStr)

        return text

    def _linkConverter(self, regexMatch, remark):
        document = remark.document
        documentTree = remark.documentTree 
        
        searchName = unixDirectoryName(regexMatch.group(2))
        includeName = regexMatch.group(2)
    
        linkDocument, unique = documentTree.findDocument(searchName, document.relativeDirectory, 
                                                         checkShorter = False)

        if not unique:
            # We don't accept ambiguous links.
            remark.reportWarning('Include filename ' + searchName + 
                                 ' is ambiguous. Skipping linking.', 
                                 'ambiguous-include')
            linkDocument = None
        
        if linkDocument == None:
            # No file was found. Skip linking.
            return regexMatch.group(0)

        linkName = unixRelativePath(document.relativeDirectory, linkDocument.relativeName) + '.htm'
        return regexMatch.group(1) + '<a href = "' + linkName + '">' + includeName + '</a>' + regexMatch.group(3).rstrip()

registerMacro('CppCode', CppCode_Macro())
Пример #9
0
from Remark.Macro_Registry import registerMacro
from Remark.FileSystem import markdownRegion


class Verbatim_Macro(object):
    def name(self):
        return 'Verbatim'

    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})

    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []

    def postConversion(self, remark):
        None


registerMacro('Verbatim', Verbatim_Macro())
Пример #10
0
        for linkFileName in parameter:
            linkDocument, unique = documentTree.findDocument(
                linkFileName, document.relativeDirectory)

            if not unique:
                remark.reporter.reportAmbiguousDocument(linkFileName)

            if linkDocument == None:
                remark.reporter.reportMissingDocument(linkFileName)
                continue

            linkTarget = unixRelativePath(document.relativeDirectory,
                                          linkDocument.relativeName)
            text.append(outputDocumentName(linkTarget))
            if len(parameter) > 1:
                text += ['']

        return text

    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []

    def postConversion(self, remark):
        None


registerMacro('Ref', Ref_Macro())
Пример #11
0
            '" />',
            '<script type="text/javascript">',
            "hs.graphicsDir = '" + graphicsDir + "/';",
            'hs.showCredits = false;',
            '</script>',
        ]

    def postConversion(self, remark):
        scriptDirectory = sys.path[0]

        copyNameSet = [
            './remark_files/highslide/highslide.css',
            './remark_files/highslide/highslide-full.js'
        ]

        for name in copyNameSet:
            copyIfNecessary(name, remarkDirectory(), name,
                            remark.outputRootDirectory)
            copyIfNecessary(name, remarkDirectory(), name,
                            remark.outputRootDirectory)

        highslideSource = os.path.join(remarkDirectory(),
                                       './remark_files/highslide/graphics')
        highslideTarget = os.path.join(remark.outputRootDirectory,
                                       './remark_files/highslide/graphics')
        if not pathExists(highslideTarget):
            copyTree(highslideSource, highslideTarget)


registerMacro('Gallery', Gallery_Macro())
Пример #12
0
class Equation_Macro(object):
    def __init__(self, leftSymbol, rightSymbol):
        self.leftSymbol = leftSymbol
        self.rightSymbol = rightSymbol

    def name(self):
        return 'Equation'

    def expand(self, parameter, remark):
        text = parameter

        if len(text) >  0:
            text[0] = self.leftSymbol + text[0]
            text[-1] += self.rightSymbol

        return text

    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []                

    def postConversion(self, remark):
        None

registerMacro('Equation', Equation_Macro("''", "''"))
registerMacro('Equation_Latex', Equation_Macro('$', '$'))
registerMacro('Equation_Latex_D', Equation_Macro('$$', '$$'))
Пример #13
0
        # 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})

    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []

    def postConversion(self, remark):
        None


registerMacro('ParentList', ParentList_Macro())
Пример #14
0
            #
            # * it has the proper depth, and
            # * it matches, or its child matches, or it
            #   has at least two children which have
            #   matching descendants.
            #
            # This retains the ancestor-descendant 
            # relation, but not the parent-child relation.
            report = ((match or 
                      childMatches > 0 or
                      usefulBranches > 1) and
                      depth >= self.minDepth)
        
        if report:
            # Add this document to the list of links.
            linkText = self.remark.remarkLink(
                    document.linkDescription(), 
                    self.document, document)
            text.append(' 1. ' + linkText)

            #text.append('')
            for line in localText:
                text.append('\t' + line)
        else:
            text += localText

        return match, (usefulBranches > 0 or match)

               
registerMacro('DocumentTree', DocumentTree_Macro())
Пример #15
0
        # 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

    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []                

    def postConversion(self, remark):
        None

registerMacro('EquationSet', EquationSet_Macro('Equation'))
registerMacro('EquationSet_Latex', EquationSet_Macro('Equation_Latex'))
registerMacro('EquationSet_Latex_D', EquationSet_Macro('Equation_Latex_D'))
Пример #16
0
# Description: Body macro
# Detail: Reads a document from file.

from Remark.FileSystem import readFile, globalOptions
from Remark.Macro_Registry import registerMacro


class Body_Macro(object):
    def name(self):
        return 'Body'

    def expand(self, parameter, remark):
        document = remark.document
        fileName = remark.documentTree.fullName(document)

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

        return text

    def expandOutput(self):
        return True

    def htmlHead(self, remark):
        return []

    def postConversion(self, remark):
        None


registerMacro('Body', Body_Macro())
Пример #17
0
                remark.reporter.reportAmbiguousDocument(linkFileName)

            if linkTarget == None:
                remark.reporter.reportMissingDocument(linkFileName)
                continue

            # Name it in the form directory/, to emphasize it is a directory.
            # Note that we escape the possible Markdown meta-characters.
            linkDescription = escapeMarkdown(linkTarget.relativeDirectory + '/')

            # Create the directory-link.
            text.append(remark.remarkLink(linkDescription,
                                          document, linkTarget))

            # If there are multiple links, we want them on their own rows.
            if len(parameter) > 1:
                text.append('')
            
        return text
    
    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []                

    def postConversion(self, remark):
        None

registerMacro('DirectoryLink', DirectoryLink_Macro())
Пример #18
0
                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})

    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []

    def postConversion(self, remark):
        None


registerMacro('Index', Index_Macro())
Пример #19
0
            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})

    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []

    def postConversion(self, remark):
        None


registerMacro('SourceChildren', SourceChildren_Macro())
Пример #20
0
from Remark.FileSystem import markdownRegion


class Example_Macro(object):
    def name(self):
        return 'Example'

    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

    def expandOutput(self):
        return False

    def htmlHead(self, remark):
        return []

    def postConversion(self, remark):
        None


registerMacro('Example', Example_Macro())