This file is indexed.

/usr/share/pyshared/gluon/contrib/markmin/markmin2latex.py is in python-gluon 1.99.7-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/usr/bin/env python
# created my Massimo Di Pierro
# license MIT/BSD/GPL
import re
import cgi
import sys
import doctest
from optparse import OptionParser

__all__ = ['render','markmin2latex']

META = 'META'
regex_newlines = re.compile('(\n\r)|(\r\n)')
regex_dd=re.compile('\$\$(?P<latex>.*?)\$\$')
regex_code = re.compile('('+META+')|(``(?P<t>.*?)``(:(?P<c>\w+))?)',re.S)
regex_title = re.compile('^#{1} (?P<t>[^\n]+)',re.M)
regex_maps = [
    (re.compile('[ \t\r]+\n'),'\n'),
    (re.compile('[ \t\r]+\n'),'\n'),
    (re.compile('\*\*(?P<t>[^\s\*]+( +[^\s\*]+)*)\*\*'),'{\\\\bf \g<t>}'),
    (re.compile("''(?P<t>[^\s']+( +[^\s']+)*)''"),'{\\it \g<t>}'),
    (re.compile('^#{6} (?P<t>[^\n]+)',re.M),'\n\n{\\\\bf \g<t>}\n'),
    (re.compile('^#{5} (?P<t>[^\n]+)',re.M),'\n\n{\\\\bf \g<t>}\n'),
    (re.compile('^#{4} (?P<t>[^\n]+)',re.M),'\n\n\\\\goodbreak\\subsubsection{\g<t>}\n'),
    (re.compile('^#{3} (?P<t>[^\n]+)',re.M),'\n\n\\\\goodbreak\\subsection{\g<t>}\n'),
    (re.compile('^#{2} (?P<t>[^\n]+)',re.M),'\n\n\\\\goodbreak\\section{\g<t>}\n'),
    (re.compile('^#{1} (?P<t>[^\n]+)',re.M),''),
    (re.compile('^\- +(?P<t>.*)',re.M),'\\\\begin{itemize}\n\\item \g<t>\n\\end{itemize}'),
    (re.compile('^\+ +(?P<t>.*)',re.M),'\\\\begin{itemize}\n\\item \g<t>\n\\end{itemize}'),
    (re.compile('\\\\end\{itemize\}\s+\\\\begin\{itemize\}'),'\n'),
    (re.compile('\n\s+\n'),'\n\n')]
regex_table = re.compile('^\-{4,}\n(?P<t>.*?)\n\-{4,}(:(?P<c>\w+))?\n',re.M|re.S)

regex_anchor = re.compile('\[\[(?P<t>\S+)\]\]')
regex_bibitem = re.compile('\-\s*\[\[(?P<t>\S+)\]\]')
regex_image_width = re.compile('\[\[(?P<t>[^\]]*?) +(?P<k>\S+) +(?P<p>left|right|center) +(?P<w>\d+px)\]\]')
regex_image = re.compile('\[\[(?P<t>[^\]]*?) +(?P<k>\S+) +(?P<p>left|right|center)\]\]')
#regex_video = re.compile('\[\[(?P<t>[^\]]*?) +(?P<k>\S+) +video\]\]')
#regex_audio = re.compile('\[\[(?P<t>[^\]]*?) +(?P<k>\S+) +audio\]\]')
regex_link = re.compile('\[\[(?P<t>[^\]]*?) +(?P<k>\S+)\]\]')
regex_auto = re.compile('(?<!["\w])(?P<k>\w+://[\w\.\-\?&%\:]+)',re.M)
regex_commas = re.compile('[ ]+(?P<t>[,;\.])')
regex_noindent = re.compile('\n\n(?P<t>[a-z])')
#regex_quote_left = re.compile('"(?=\w)')
#regex_quote_right = re.compile('(?=\w\.)"')

def latex_escape(text,pound=True):
    text=text.replace('\\','{\\textbackslash}')
    for c in '^_&$%{}': text=text.replace(c,'\\'+c)
    text=text.replace('\\{\\textbackslash\\}','{\\textbackslash}')
    if pound: text=text.replace('#','\\#')
    return text

def render(text,
           extra={},
           allowed={},
           sep='p',
           image_mapper=lambda x:x,
           chapters=False):
    #############################################################
    # replace all blocks marked with ``...``:class with META
    # store them into segments they will be treated as code
    #############################################################
    text = str(text or '')
    segments, i = [], 0
    text = regex_dd.sub('``\g<latex>``:latex ',text)
    text = regex_newlines.sub('\n',text)
    while True:
        item = regex_code.search(text,i)
        if not item: break
        if item.group()==META:
            segments.append((None,None))
            text = text[:item.start()]+META+text[item.end():]
        else:
            c = item.group('c') or ''
            if 'code' in allowed and not c in allowed['code']: c = ''
            code = item.group('t').replace('!`!','`')
            segments.append((code,c))
            text = text[:item.start()]+META+text[item.end():]
        i=item.start()+3


    #############################################################
    # do h1,h2,h3,h4,h5,h6,b,i,ol,ul and normalize spaces
    #############################################################

    title = regex_title.search(text)
    if not title: title='Title'
    else: title=title.group('t')

    text = latex_escape(text,pound=False)

    texts = text.split('## References',1)
    text = regex_anchor.sub('\\label{\g<t>}', texts[0])
    if len(texts)==2:
        text += '\n\\begin{thebibliography}{999}\n'
        text += regex_bibitem.sub('\n\\\\bibitem{\g<t>}', texts[1])
        text += '\n\\end{thebibliography}\n'

    text = '\n'.join(t.strip() for t in text.split('\n'))
    for regex, sub in regex_maps:
        text = regex.sub(sub,text)
    text=text.replace('#','\\#')
    text=text.replace('`',"'")

    #############################################################
    # process tables and blockquotes
    #############################################################
    while True:
        item = regex_table.search(text)
        if not item: break
        c = item.group('c') or ''
        if 'table' in allowed and not c in allowed['table']: c = ''
        content = item.group('t')
        if ' | ' in content:
            rows = content.replace('\n','\\\\\n').replace(' | ',' & ')
            row0,row2 = rows.split('\\\\\n',1)
            cols=row0.count(' & ')+1
            cal='{'+''.join('l' for j in range(cols))+'}'
            tabular = '\\begin{center}\n{\\begin{tabular}'+cal+'\\hline\n' + row0+'\\\\ \\hline\n'+row2 + ' \\\\ \\hline\n\\end{tabular}}\n\\end{center}'
            if row2.count('\n')>20: tabular='\\newpage\n'+tabular
            text = text[:item.start()] + tabular + text[item.end():]
        else:
            text = text[:item.start()] + '\\begin{quote}' + content + '\\end{quote}' + text[item.end():]

    #############################################################
    # deal with images, videos, audios and links
    #############################################################

    def sub(x):
        f=image_mapper(x.group('k'))
        if not f: return None
        return '\n\\begin{center}\\includegraphics[width=8cm]{%s}\\end{center}\n' % (f)
    text = regex_image_width.sub(sub,text)
    text = regex_image.sub(sub,text)

    text = regex_link.sub('{\\\\footnotesize\\href{\g<k>}{\g<t>}}', text)
    text = regex_commas.sub('\g<t>',text)
    text = regex_noindent.sub('\n\\\\noindent \g<t>',text)

    ### fix paths in images
    regex=re.compile('\\\\_[\w_]*\.(eps|png|jpg|gif)')
    while True:
        match=regex.search(text)
        if not match: break
        text=text[:match.start()]+text[match.start()+1:]
    #text = regex_quote_left.sub('``',text)
    #text = regex_quote_right.sub("''",text)

    if chapters:
        text=text.replace(r'\section*{',r'\chapter*{')
        text=text.replace(r'\section{',r'\chapter{')
        text=text.replace(r'subsection{',r'section{')

    #############################################################
    # process all code text
    #############################################################
    parts = text.split(META)
    text = parts[0]
    authors = []
    for i,(code,b) in enumerate(segments):
        if code==None:
            html = META
        else:
            if b=='hidden':
                html=''
            elif b=='author':
                author = latex_escape(code.strip())
                authors.append(author)
                html=''
            elif b=='inxx':
                html='\inxx{%s}' % latex_escape(code)
            elif b=='cite':
                html='~\cite{%s}' % latex_escape(code.strip())
            elif b=='ref':
                html='~\ref{%s}' % latex_escape(code.strip())
            elif b=='latex':
                if '\n' in code:
                    html='\n\\begin{equation}\n%s\n\\end{equation}\n' % code.strip()
                else:
                    html='$%s$' % code.strip()
            elif b=='latex_eqnarray':
                code=code.strip()
                code='\\\\'.join(x.replace('=','&=&',1) for x in code.split('\\\\'))
                html='\n\\begin{eqnarray}\n%s\n\\end{eqnarray}\n' % code
            elif b.startswith('latex_'):
                key=b[6:]
                html='\\begin{%s}%s\\end{%s}' % (key,code,key)
            elif b in extra:
                if code[:1]=='\n': code=code[1:]
                if code[-1:]=='\n': code=code[:-1]
                html = extra[b](code)
            elif code[:1]=='\n' or code[:-1]=='\n':
                if code[:1]=='\n': code=code[1:]
                if code[-1:]=='\n': code=code[:-1]
                if code.startswith('<') or code.startswith('{{') or code.startswith('http'):
                    html = '\\begin{lstlisting}[keywords={}]\n%s\n\\end{lstlisting}' % code
                else:
                    html = '\\begin{lstlisting}\n%s\n\\end{lstlisting}' % code
            else:
                if code[:1]=='\n': code=code[1:]
                if code[-1:]=='\n': code=code[:-1]
                html = '{\\ft %s}' % latex_escape(code)
        try:
            text = text+html+parts[i+1]
        except:
            text = text + '... WIKI PROCESSING ERROR ...'
            break
    text =  text.replace(' ~\\cite','~\\cite')
    return text, title, authors

WRAPPER = """
\\documentclass[12pt]{article}
\\usepackage{hyperref}
\\usepackage{listings}
\\usepackage{upquote}
\\usepackage{color}
\\usepackage{graphicx}
\\usepackage{grffile}
\\usepackage[utf8x]{inputenc}
\\definecolor{lg}{rgb}{0.9,0.9,0.9}
\\definecolor{dg}{rgb}{0.3,0.3,0.3}
\\def\\ft{\\small\\tt}
\\lstset{
   basicstyle=\\footnotesize,
   breaklines=true, basicstyle=\\ttfamily\\color{black}\\footnotesize,
   keywordstyle=\\bf\\ttfamily,
   commentstyle=\\it\\ttfamily,
   stringstyle=\\color{dg}\\it\\ttfamily,
   numbers=left, numberstyle=\\color{dg}\\tiny, stepnumber=1, numbersep=5pt,
   backgroundcolor=\\color{lg}, tabsize=4, showspaces=false,
   showstringspaces=false
}
\\title{%(title)s}
\\author{%(author)s}
\\begin{document}
\\maketitle
\\tableofcontents
\\newpage
%(body)s
\\end{document}
"""

def markmin2latex(data, image_mapper=lambda x:x, extra={},
                  wrapper=WRAPPER):
    body, title, authors = render(data, extra=extra, image_mapper=image_mapper)
    author = '\n\\and\n'.join(a.replace('\n','\\\\\n\\footnotesize ') for a in authors)
    return wrapper % dict(title=title, author=author, body=body)

if __name__ == '__main__':
    parser = OptionParser()
    parser.add_option("-i", "--info", dest="info",
                      help="markmin help")
    parser.add_option("-t", "--test", dest="test", action="store_true",
                      default=False)
    parser.add_option("-n", "--no_wrapper", dest="no_wrapper",
                      action="store_true",default=False)
    parser.add_option("-c", "--chapters", dest="chapters",action="store_true",
                      default=False,help="switch section for chapter")
    parser.add_option("-w", "--wrapper", dest="wrapper", default=False,
                      help="latex file containing header and footer")

    (options, args) = parser.parse_args()
    if options.info:
        import markmin2html
        markmin2latex(markmin2html.__doc__)
    elif options.test:
        doctest.testmod()
    else:
        if options.wrapper:
            fwrapper = open(options.wrapper,'rb')
            try:
                wrapper = fwrapper.read()
            finally:
                fwrapper.close()
        elif options.no_wrapper:
            wrapper  = '%(body)s'
        else:
            wrapper = WRAPPER
        for f in args:
            fargs = open(f,'r')
            content_data = []
            try:
                content_data.append(fargs.read())
            finally:
                fargs.close()
        content = '\n'.join(content_data)
        output= markmin2latex(content,
                              wrapper=wrapper,
                              chapters=options.chapters)
        print output