def read(self, source_path): """Parse content and metadata of markdown files""" self._source_path = source_path self._md = Markdown(extensions=[ 'markdown.extensions.toc', 'markdown.extensions.tables', 'markdown.extensions.meta', 'markdown.extensions.extra', codehilite.CodeHiliteExtension(css_class='highlight'), ], ) img_path = os.path.dirname(source_path) + '/img/' \ + os.path.basename(source_path)[:-3] lst_path = os.path.dirname(source_path) + '/lst/' \ + os.path.basename(source_path)[:-3] tbl_path = os.path.dirname(source_path) + '/tbl/' \ + os.path.basename(source_path)[:-3] build.path = [img_path, lst_path, tbl_path] + build.path with open(source_path) as fd: text = fd.read() if hasattr(text, 'decode'): # Python 2 text = text.decode('utf-8') for m in re.finditer('```python(?P<code>.*?)```', text, re.DOTALL): new_block = (u'\n%--\npython: |\n' + u'\n'.join( [u' ' + s for s in m.group('code').strip().split(u'\n')]) + u'\n--%\n') text = text.replace(m.group(0), new_block) text = build.MD(text) # Process internal links for m in re.finditer('%link:(?P<link>[\w/-]+)%', text): full = m.group(0) link = m.group('link') print('link', link, full) if link not in links: raise Exception(u'%s not a key in %s' % (link, links)) text = text.replace(full, '<%s/%s>' % (SITEURL, links[link])) for m in re.finditer('%url:(?P<link>[\w/-]+)%', text): full = m.group(0) link = m.group('link') print('url', link, full) if link not in links: raise Exception(u'%s not a key in %s' % (link, links)) text = text.replace(full, '%s/%s' % (SITEURL, links[link])) for m in re.finditer('%static:(?P<link>[\w/.-]+)%', text): full = m.group(0) link = m.group('link') print('static', link, full) text = text.replace(full, '<%s/%s>' % (SITEURL, link)) text = text.replace(root, u'') text = HTMLFilter.DOI(text) content = self._md.convert(text) for var, val in const.items(): content = content.replace(u'$%s$' % var, str(val)) for item_type in ITEM_TYPES: content = content.replace( item_type, u'<span class="item-type">%s</span>' % item_type.lower()) metadata = self._parse_metadata(self._md.Meta) build.path = build.path[3:] return content, metadata
def read(self, source_path): """Parse content and metadata of markdown files""" self._source_path = source_path self._md = Markdown(extensions=[ 'markdown.extensions.toc', 'markdown.extensions.tables', 'markdown.extensions.meta', 'markdown.extensions.extra', codehilite.CodeHiliteExtension(css_class='highlight'), ], ) # self._md = Markdown( # extensions=self.extensions + [TocExtension(title='Overview'), # TableExtension()], # extpeension_configs=self.extensions) img_path = os.path.dirname(source_path) + '/img/' \ + os.path.basename(source_path)[:-3] lst_path = os.path.dirname(source_path) + '/lst/' \ + os.path.basename(source_path)[:-3] tbl_path = os.path.dirname(source_path) + '/tbl/' \ + os.path.basename(source_path)[:-3] build.path = [img_path, lst_path, tbl_path] + build.path with open(source_path) as fd: text = fd.read() text = build.MD(text) # Process internal links for m in re.finditer('%link:(?P<link>[\w/-]+)%', text): full = m.group(0) link = m.group('link') print('link', link, full) if link not in links: raise Exception(u'%s not a key in %s' % (link, links)) text = text.replace(full, '<%s/%s>' % (SITEURL, links[link])) for m in re.finditer('%url:(?P<link>[\w/-]+)%', text): full = m.group(0) link = m.group('link') print('url', link, full) if link not in links: raise Exception(u'%s not a key in %s' % (link, links)) text = text.replace(full, '%s/%s' % (SITEURL, links[link])) for m in re.finditer('%static:(?P<link>[\w/.-]+)%', text): full = m.group(0) link = m.group('link') print('static', link, full) text = text.replace(full, '<%s/%s>' % (SITEURL, link)) text = text.replace(root, u'') text = HTMLFilter.DOI(text) content = self._md.convert(text) for var, val in const.items(): content = content.replace(u'$%s$' % var, str(val)) for item_type in ITEM_TYPES: content = content.replace( item_type, u'<span class="item-type">%s</span>' % item_type.lower()) metadata = self._parse_metadata(self._md.Meta) build.path = build.path[3:] return content, metadata
#!/usr/bin/env python #-*- coding:utf-8 -*- """ This file is part of YAMLDoc. YAMLDoc is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. YAMLDoc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with YAMLDoc. If not, see <http://www.gnu.org/licenses/>. """ import yamldoc from academicmarkdown import build from yamldoc.py3compat import * fd = yamldoc.DocFactory(yamldoc) md = build.MD(str(fd)) build.TOCAnchorHeaders = True build.HTML(str(fd), u'readme.html') print(md) open(u'readme.md', u'w').write(safe_encode(md))
#!/usr/bin/env python #-*- coding:utf-8 -*- """ This file is part of QProgEdit. QProgEdit is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. QProgEdit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with QProgEdit. If not, see <http://www.gnu.org/licenses/>. """ import yamldoc import QProgEdit from QProgEdit.py3compat import * from academicmarkdown import build df = yamldoc.DocFactory(QProgEdit) s = str(df) print(s) build.setStyle('modern') build.MD(s, u'readme.md') build.PDF(s, u'readme.pdf')
#!/usr/bin/env python """ This file is part of qnotero. qnotero is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. qnotero is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with qnotero. If not, see <http://www.gnu.org/licenses/>. """ from academicmarkdown import build build.MD('readme-src.md', 'readme.md')
# coding=utf-8 import re from academicmarkdown import build build.postMarkdownFilters = [] with open('readme-template.md') as fd: text = fd.read() for m in re.finditer('```python(?P<code>.*?)```', text, re.DOTALL): new_block = ( u'\n%--\npython: |\n' + u'\n'.join([u' '+ s for s in m.group('code').strip().split(u'\n')]) + u'\n--%\n' ) text = text.replace(m.group(0), new_block) md = build.MD(text) md = md.replace('~~~ .python', '```python') md = md.replace('\n~~~', '```') with open('readme.md', 'w') as fd: fd.write(md)