Exemplo n.º 1
0
 def _aHelp(self, parts):
     # {{aHelp|HID|VISIBILITY|CONTENT}}
     if len(parts) == 4:
         return """<ahelp hid="{HID}" visibility="{VISIBILITY}">{CONTENT}</ahelp>""".format(
             HID=h.escape_html(parts[1]), VISIBILITY=("visible" if parts[2] == "visible" else "hidden"), 
             CONTENT=h.escape_html(parts[3]))
     return self._write_template_error(parts)
Exemplo n.º 2
0
 def link(self, content, link, title=""):
     title = h.escape_html(title)
     if title is None:
         title = ""
     if not re.match("(http://|https://|ftp://|vnd.sun.star.help://)", link):
         link = re.sub("^(./|../)", "", link)
         link = re.sub(".md$", ".xhp", link)
         link = "{ID}/{LINK}".format(ID=h.escape_html(self.identifier), LINK=link)
     return """<link href="{HREF}" name="{NAME}">{CONTENT}</link>""".format(
         HREF=link, NAME=title, CONTENT=content)
Exemplo n.º 3
0
 def block_code(self, text, lang):
     if not lang:
         if isinstance(text, unicode):
             text = text.encode('utf-8')
         return '<pre><code>%s</code></pre>' % h.escape_html(text.strip())
     if self.use_pygments:
         lexer = get_lexer_by_name(lang, stripall=True)
         formatter = HtmlFormatter()
         return highlight(text, lexer, formatter)
     return '<pre class="language-%s"><code>%s</code></pre>' % (
         lang, h.escape_html(text.strip()))
Exemplo n.º 4
0
 def block_code(self, text, lang):
     if not lang:
         if isinstance(text, unicode):
             text = text.encode('utf-8')
         return '<pre><code>%s</code></pre>' % h.escape_html(text.strip())
     if self.use_pygments:
         lexer = get_lexer_by_name(lang, stripall=True)
         formatter = HtmlFormatter()
         return highlight(text, lexer, formatter)
     return '<pre class="language-%s"><code>%s</code></pre>' % (
         lang, h.escape_html(text.strip())
     )
Exemplo n.º 5
0
    def block_code(self, text, lang):
        if not lang:
            return '\n<pre><code>%s</code></pre>\n' % \
                h.escape_html(text.strip())
        if str(lang).strip() == 'latex-block':
            md_str = latex2markdown.LaTeX2Markdown(text).to_markdown()
            return md_str

        try:
            lexer = get_lexer_by_name(lang, stripall=True)
            formatter = HtmlFormatter()
            return highlight(text, lexer, formatter)
        except pygments.util.ClassNotFound:
            return '\n<pre><code>%s</code></pre>\n' % \
                h.escape_html(text.strip())
Exemplo n.º 6
0
 def block_code(self, text, lang):
     if not lang:
         if isinstance(text, unicode):
             text = text.encode('utf-8')
         return '<pre><code>%s</code></pre>' % h.escape_html(text.strip())
     if self.use_pygments:
         try:
             # if the language can not be found, it will raise
             lexer = get_lexer_by_name(lang.lower(), stripall=True)
             formatter = HtmlFormatter()
             return highlight(text, lexer, formatter)
         except:
             pass
     return '<pre class="language-%s"><code>%s</code></pre>' % (
         lang, h.escape_html(text.strip()))
Exemplo n.º 7
0
    def block_code(self, text, lang):
        if not lang:
            return '\n<pre><code>%s</code></pre>\n' % \
                h.escape_html(text.strip())
        if str(lang).strip() == 'latex-block':
            md_str = latex2markdown.LaTeX2Markdown(text).to_markdown()
            return md_str

        try:
            lexer = get_lexer_by_name(lang, stripall=True)
            formatter = HtmlFormatter()
            return highlight(text, lexer, formatter)
        except pygments.util.ClassNotFound:
            return '\n<pre><code>%s</code></pre>\n' % \
                h.escape_html(text.strip())
Exemplo n.º 8
0
    def blockcode(self, text, lang):
        if not lang:
            return '\n<pre><code>{}</code></pre>\n'.format(houdini.escape_html(text.strip()))

        lexer = get_lexer_by_name(lang)
        formatter = HtmlFormatter()
        return highlight(text, lexer, formatter)
Exemplo n.º 9
0
 def _Variable(self, parts):
     # {{Variable|ID|VISIBILITY|CONTENT}}
     if len(parts) == 4:
         return """<variable id="{ID}" visibility="{VISIBILITY}">{CONTENT}</variable>""".format(
             ID=self._generate_id("var"), VISIBILITY=("visible" if parts[2] == "visible" else "hidden"), 
             CONTENT=h.escape_html(parts[3]))
     return self._write_template_error(parts)
Exemplo n.º 10
0
    def blockcode(self, text, lang):
        if not lang:
            return '\n<pre><code>{}</code></pre>\n'.format(houdini.escape_html(text.strip()))

        lexer = get_lexer_by_name(lang)
        formatter = HtmlFormatter()
        return highlight(text, lexer, formatter)
Exemplo n.º 11
0
 def block_code(self, text, lang):
     if not lang:
         return '\n<pre><code>%s</code></pre>\n' % \
             h.escape_html(text.strip())
     lexer = get_lexer_by_name(lang, stripall=True)
     formatter = CodeHtmlFormatter()
     return highlight(text, lexer, formatter)
Exemplo n.º 12
0
 def block_code(self, text, lang):
     if not lang:
         if isinstance(text, unicode):
             text = text.encode('utf-8')
         return '<pre><code>%s</code></pre>' % h.escape_html(text.strip())
     if hasattr(self, 'use_pygments') and self.use_pygments:
         try:
             # if the language can not be found, it will raise
             lexer = get_lexer_by_name(lang.lower(), stripall=True)
             formatter = HtmlFormatter()
             return highlight(text, lexer, formatter)
         except:
             pass
     return '<pre class="language-%s"><code>%s</code></pre>' % (
         lang, h.escape_html(text.strip())
     )
Exemplo n.º 13
0
 def image(self, link, title="", alt=""):
     # todo resolve image location and width/height?
     if link.startswith(self.base_addr):
         link = link[len(self.base_addr):]
         link = "{ID}/{LINK}".format(ID=h.escape_html(self.identifier), LINK=link)
     return """<image id="{ID}" src="{SRC}">{CONTENT}</image>""".format(
         ID=self._generate_id("img"), SRC=link, CONTENT=title)
Exemplo n.º 14
0
 def block_code(self, text, lang):
     try:
         lexer = get_lexer_by_name(lang, stripall=True)
     except ClassNotFound:
         return '\n<pre><code>%s</code></pre>\n' % h.escape_html(text.strip())
     formatter = HtmlFormatter()
     return highlight(text, lexer, formatter)
Exemplo n.º 15
0
 def block_code(self, text, lang):
     if not lang:
         return '\n<pre><code>%s</code></pre>\n' % \
             houdini.escape_html(text.strip())
     lexer = get_lexer_by_name(lang, stripall=True)
     formatter = HtmlFormatter()
     return highlight(text, lexer, formatter)
Exemplo n.º 16
0
 def _code_no_lexer(self, text):
     # encode to utf8 string
     text = text.encode(charset).strip()
     return ("""
         <div class="highlight">
           <pre><code>%s</code></pre>
         </div>
         """ % houdini.escape_html(text))
Exemplo n.º 17
0
 def _Tip(self, parts):
     # {{Tip|CONTENT}}, {{Caution|CONTENT}} or {{Warning|CONTENT}}
     if len(parts) == 2:
         role = parts[0].lower()
         if role == "caution":
             role = "warning"
         return self.paragraph(h.escape_html(parts[1]), role=role)
     return self._write_template_error(parts)
Exemplo n.º 18
0
    def blockcode(self, text, lang):
        if not lang:
            return '\n<pre><code>{}</code></pre>\n'.format(
                h.escape_html(text.strip()))

        lexer = get_lexer_by_name(lang, stripall=True)
        formatter = HtmlFormatter()

        return highlight(m.smartypants(text), lexer, formatter)
Exemplo n.º 19
0
 def block_code(self, text, lang):
     try:
         lexer = get_lexer_by_name(lang, stripall=True)
     except ClassNotFound:
         text = escape_html(text.strip())
         return '\n<pre><code>%s</code></pre>\n' % text
     else:
         formatter = HtmlFormatter()
         return highlight(text, lexer, formatter)
Exemplo n.º 20
0
 def block_code(self, text, lang):
     if not lang:
         return ('\n<pre><code>%s</code></pre>\n'
                 % h.escape_html(text.strip()))
     elif lang == 'blockdiag':
         return generatoBlockdiag(text)
     lexer = get_lexer_by_name(lang, stripall=True)
     formatter = HtmlFormatter()
     return highlight(text, lexer, formatter)
Exemplo n.º 21
0
def txt_reader(path):
    post = html_reader(path)
    content = post.content.encode("utf-8")
    content = escape_html(content)
    content = content.replace(
        "\n",
        "<br />"
    )
    post.content = to_unicode(content)
    return post
Exemplo n.º 22
0
    def blockcode(self, text, lang):
        """Return HTML for block code"""
        if not lang:
            return '\n<pre><code>{}</code></pre>\n'.format(
                h.escape_html(text.strip()))

        lexer = get_lexer_by_name(lang, stripall=True)
        formatter = HtmlFormatter()

        return highlight(text, lexer, formatter)
Exemplo n.º 23
0
Arquivo: parser.py Projeto: a0x/lilac
 def _code_no_lexer(self, text):
     # encode to utf8 string
     text = text.encode(charset).strip()
     return(
         """
         <div class="highlight">
           <pre><code>%s</code></pre>
         </div>
         """ % houdini.escape_html(text)
     )
Exemplo n.º 24
0
    def blockcode(self, text, lang):
        try:
            lexer = get_lexer_by_name(lang, stripall=False)
        except ClassNotFound:
            lexer = None

        if lexer:
            formatter = HtmlFormatter(linenos=True)
            return highlight(text, lexer, formatter)
        # default
        return '\n<pre><code>{}</code></pre>\n'.format(houdini.escape_html(text.strip()))
Exemplo n.º 25
0
    def blockcode(self, text, lang):
        try:
            lexer = get_lexer_by_name(lang, stripall=True)
        except ClassNotFound:
            lexer = None

        if lexer:
            formatter = HtmlFormatter(noclasses=True)
            return highlight(text, lexer, formatter)
        # default
        return '\n<pre><code>{}</code></pre>\n'.format(
                            h.escape_html(text.strip()))
Exemplo n.º 26
0
    def doc_header(self, inline_render):
        # todo meta/history
        return """<?xml version="1.0" encoding="UTF-8"?>
<helpdocument version="1.0">
 <meta>
  <topic id="topic_" indexer="include">
  <title id="tit" xml-lang="{LANG}"></title>
  <filename>{FILENAME}</filename>
 </topic>
 </meta>
<body>\n""".format(
        LANG=self.lang, CREATED="", EDITED="", 
        FILENAME=h.escape_html(self._get_file_name()))
Exemplo n.º 27
0
def parse_catsup_meta(lines, path=None):
    meta = read_base_meta(path)
    if lines[0][0] == "#":
        meta.title = escape_html(lines.pop(0)[1:].strip())
    for line in lines:
        if not line:
            continue
        if ":" not in line:
            not_valid(path)
        name, value = line.split(':', 1)
        name = name.strip().lstrip('-').strip().lower()
        meta[name] = value.strip()
    return meta
Exemplo n.º 28
0
 def _Bookmark(self, parts):
     # {{Bookmark|BRANCH|COMPONENTS|VALUES}}
     # {{Bookmark|BRANCH|VALUES}}
     if len(parts) == 3:
         parts.insert(2, "")
     if len(parts) > 3:
         id = self._generate_id("bk")
         if parts[2]:
             id = id + "_".join([p.strip().lower() for p in parts[2].split(",")])
         values = parts[3].split("||") if len(parts) > 3 else []
         return """<bookmark branch="{BRANCH}" id="{ID}" lang="{LANG}">{VALUES}</bookmark>""".format(
             BRANCH=h.escape_html(parts[1]), ID=id, LANG=self.lang, 
             VALUES="\n".join(["<bookmark_value xml-lang=\"{LANG}\">".format(LANG=self.lang) + h.escape_html(v) + "</bookmark_value>" for v in values]))
     return self._write_template_error(parts)
Exemplo n.º 29
0
Arquivo: parser.py Projeto: mozii/golb
    def block_code(self, text, lang):

        if not lang:
            text = text.encode(charset).strip()
            return (
                """\n<div class="highlight">
                <pre><code>%s</code></pre>
                </div>\n""" % h.escape_html(text)
            )

        lexer = get_lexer_by_name(lang, stripall=True)
        formatter = HtmlFormatter()

        return highlight(text, lexer, formatter)
Exemplo n.º 30
0
def parse_catsup_meta(lines, path=None):
    meta = ObjectDict()
    title_line = lines.pop(0)
    if title_line[0] != "#":
        not_valid(path)
    meta.title = escape_html(title_line[1:].strip())
    for line in lines:
        if not line:
            continue
        if ":" not in line:
            not_valid(path)
        name, value = line.split(':', 1)
        name = name.strip().lstrip('-').strip().lower()
        meta[name] = value.strip()
    return meta
Exemplo n.º 31
0
    def blockcode(self, text, lang):
        cssclass = 'code-highlighted'
        try:
            lexer = get_lexer_by_name(lang, stripall=True)
        except ClassNotFound:
            lexer = None

        if lexer:
            # Fixme: it would be better to have a single css file created,
            # which is possible! but right now in this early phase that's
            # a distraction
            formatter = HtmlFormatter(noclasses=True, cssclass=cssclass)
            return highlight(text, lexer, formatter)
        # no lexer
        return '\n<div class="{1}"><pre>{0}</pre></div>\n'.format(
                houdini.escape_html(text.strip()), cssclass)
Exemplo n.º 32
0
    def blockcode(self, text, lang):
        cssclass = 'code-highlighted'
        try:
            lexer = get_lexer_by_name(lang, stripall=True)
        except ClassNotFound:
            lexer = None

        if lexer:
            # Fixme: it would be better to have a single css file created,
            # which is possible! but right now in this early phase that's
            # a distraction
            formatter = HtmlFormatter(noclasses=True, cssclass=cssclass)
            return highlight(text, lexer, formatter)
        # no lexer
        return '\n<div class="{1}"><pre>{0}</pre></div>\n'.format(
            houdini.escape_html(text.strip()), cssclass)
Exemplo n.º 33
0
    def block_code(self, text, lang):
        output = ''

        if not lang:
            return '\n<pre><code>%s</code></pre>\n' % \
                h.escape_html(text.strip())

        try:
            lexer = get_lexer_by_name(lang, stripall=True)
        except:
            output += '<b>Language "' + lang + '" not supported</b>'
            lexer = get_lexer_by_name(text, stripall=True)

        output += highlight(text, lexer, formatter)

        return output
Exemplo n.º 34
0
            def block_code(self, text, lang):
                # 使用run_prettify.js自动识别及高亮
                content = h.escape_html(text.strip())
                style = ' class="prettyprint linenums"'
                if lang is not None:
                    if lang.lower() == 'plain':
                        style = ''
                    elif lang.lower() == 'code':
                        style = ' class="prettyprint linenums"'
                    elif lang.lower() == 'flow':
                        content = text.strip()
                        style = ' class="ns-flow-chart"'
                    elif lang.lower() == 'seq':
                        content = text.strip()
                        style = ' class="ns-seq-chart"'
                else:
                    style = ''

                return '\n<pre><code%s>%s</code></pre>\n' % (style, content)
Exemplo n.º 35
0
 def _code_no_lexer(self, text):
     text = text.encode('utf8')
     return '<pre><code>{}</code></pre>'.format(escape_html(text))
Exemplo n.º 36
0
def test_output_preserves_unicodeness():
    string = u'héllo < hëllo'
    escaped = houdini.escape_html(string)
    assert_equals(escaped, u'héllo &lt; hëllo')
Exemplo n.º 37
0
def test_doesnt_escape_stuff_if_it_doesnt_need_to():
    string = u'hello'
    escaped = houdini.escape_html(string)
    assert string is escaped
Exemplo n.º 38
0
 def block_code(self, text, lang):
     text = h.escape_html(text.encode('utf-8'), 1).decode('utf-8')
     lang = ' data-lang="{0}"'.format(lang) if lang else ''
     
     return '<pre><code{0}>{1}</code></pre>'.format(lang, text)
Exemplo n.º 39
0
 def autolink(self, link, is_email):
     url = h.escape_html(link)
     return """<link href="{URL}">{URL}</link>""".format(URL=url)
Exemplo n.º 40
0
 def math(self, text, displaymode):
     # not supported
     return h.escape_html(text)
Exemplo n.º 41
0
 def normal_text(self, text):
     return h.escape_html(text.strip())
Exemplo n.º 42
0
def test_escapes_stuff_if_necessary():
    string = u"<>&;\""
    escaped = houdini.escape_html(string)
    assert_equals(escaped, u'&lt;&gt;&amp;;&quot;')
Exemplo n.º 43
0
def test_output_preserves_unicodeness():
    string = u'héllo < hëllo'
    escaped = houdini.escape_html(string)
    assert_equals(escaped, u'héllo &lt; hëllo')
Exemplo n.º 44
0
 def codespan(self, text):
     return h.escape_html(text)
Exemplo n.º 45
0
def test_doesnt_escape_stuff_if_it_doesnt_need_to():
    string = u'hello'
    escaped = houdini.escape_html(string)
    assert string is escaped
Exemplo n.º 46
0
 def blockcode(self, text, lang=""):
     return self.paragraph("<br />".join(h.escape_html(text).split("\n")), role="code")
Exemplo n.º 47
0
def test_escapes_stuff_if_necessary():
    string = u"<>&;\""
    escaped = houdini.escape_html(string)
    assert_equals(escaped, u'&lt;&gt;&amp;;&quot;')
Exemplo n.º 48
0
    def block_code(self, text, lang):
        text = h.escape_html(text.encode('utf-8'), 1).decode('utf-8')
        lang = ' data-lang="{0}"'.format(lang) if lang else ''

        return '<pre><code{0}>{1}</code></pre>'.format(lang, text)