示例#1
0
def convert_md_to_rst():
    doc = pandoc.Document()
    doc.markdown = open('README.md').read()

    filtered = str(doc.rst)
    filtered = re.sub(
        'Table of Contents\n~~~~~~~~~~~~~~~~~.*Installation\n------------',
        'Installation\n------------',
        filtered,
        flags=re.DOTALL)
    filtered = re.sub(
        '\n`\|Build Status\| <https://travis-ci.org/csu/pyquora>`_ `\|Latest\nVersion\| <https://pypi.python.org/pypi/quora/>`_\n',
        '',
        filtered,
        flags=re.DOTALL)
    filtered = re.sub('`\|Gitter\|.*>`_', '', filtered, flags=re.DOTALL)
    filtered = re.sub('`\|HuBoard\|.*`_', '', filtered, flags=re.DOTALL)
    filtered = re.sub('Contribute\n----------.*',
                      '',
                      filtered,
                      flags=re.DOTALL)

    f = open('README', 'w+')
    f.write(filtered)
    f.close()

    f = open('README.rst', 'w+')
    f.write(filtered)
    f.close()
示例#2
0
def convert_html_to_rst(html):
    """Returns ReSt version of given HTML"""

    doc = pandoc.Document()
    doc.html = html

    return doc.rst
示例#3
0
文件: server.py 项目: csu/progress
 def goals_page():
     doc = pandoc.Document()
     doc.markdown = p.get_file('_goals.md')
     content = unicode(str(doc.html), "utf-8")
     return render_template('default.html',
                            content=content,
                            edit_link=get_edit_link())
示例#4
0
 def run(self):
     import pandoc
     doc = pandoc.Document()
     doc.markdown = open('README.md').read()
     f = open('README.txt', 'w+')
     f.write(doc.rst)
     f.close()
示例#5
0
def get_long_description():
    long_description = open('README.md').read()
    try:
        import subprocess
        import pandoc

        process = subprocess.Popen(['which pandoc'],
                                   shell=True,
                                   stdout=subprocess.PIPE,
                                   universal_newlines=True)

        pandoc_path = process.communicate()[0]
        pandoc_path = pandoc_path.strip('\n')

        pandoc.core.PANDOC_PATH = pandoc_path

        doc = pandoc.Document()
        doc.markdown = long_description
        long_description = doc.rst
        open("README.rst", "w").write(doc.rst)
    except:
        if os.path.exists("README.rst"):
            long_description = open("README.rst").read()
        else:
            print("Could not find pandoc or convert properly")
            print(
                "  make sure you have pandoc (system) and pyandoc (python module) installed"
            )

    return long_description
示例#6
0
def contents_version(url, paths):
    try:
        version = redmine.version.get(paths[2])
    except:
        print("Version not found : " + paths[2])
        return {"title": "TRYPOT Redmnine", "text": "존재하지 않는 버젼입니다"}

    doc = pandoc.Document()
    doc.html = version.description.encode('utf-8')

    content = {
        "title":
        version.project.name + " @" + version.name,
        "title_link":
        url,
        "color":
        "#7c97d1",
        "text":
        str(doc.plain.decode('utf-8')),
        "fields": [{
            "title": "상태",
            "value": version.status,
            "short": True
        }, {
            "title": "완료기한",
            "value": version.due_date.strftime("%Y/%m/%d"),
            "short": True
        }]
    }

    return content
示例#7
0
def contents_issue(url, paths):
    try:
        issue = redmine.issue.get(paths[2])
    except:
        print("Issue not found : " + paths[2])
        return {"title": "TRYPOT Redmine", "text": "존재하지 않는 이슈입니다"}

    user = redmine.user.get(issue.assigned_to.id)
    author = redmine.user.get(issue.author.id)

    doc = pandoc.Document()
    doc.html = issue.description.encode('utf-8')

    if "created_on" in dir(issue):
        create_date = " 이(가) " + issue.created_on.strftime("%Y/%m/%d") + "에 생성"
    else:
        create_date = ""

    if "due_date" in dir(issue):
        due_date = issue.due_date.strftime("%Y/%m/%d")
    else:
        due_date = "없음"

    content = {
        "title":
        issue.project.name + " #" + paths[2] + " " + issue.subject,
        "title_link":
        url,
        "color":
        "#7cd197",
        "author_name":
        issue.author.name + "(<@" + author.login + ">)" + create_date,
        "fields": [{
            "title": "담당자",
            "value": issue.assigned_to.name + " <@" + user.login + ">",
            "short": False
        }, {
            "title": "상태",
            "value": issue.status.name,
            "short": True
        }, {
            "title": "우선순위",
            "value": issue.priority.name,
            "short": True
        }, {
            "title": "시작시간",
            "value": issue.start_date.strftime("%Y/%m/%d"),
            "short": True
        }, {
            "title": "완료기한",
            "value": due_date,
            "short": True
        }],
        "text":
        str(doc.plain.decode('utf-8')),
        "footer":
        "TRYPOT Studios Inc."
    }
    return content
示例#8
0
def pandoc_read_md(fname):
    if 'PANDOC_PATH' not in os.environ:
        raise ImportError("No pandoc path to use")
    import pandoc
    pandoc.core.PANDOC_PATH = os.environ['PANDOC_PATH']
    doc = pandoc.Document()
    doc.markdown = read(fname)
    return doc.rst
def markdown_to_rst(src):
    pandoc.core.PANDOC_PATH = "/usr/local/bin/pandoc"
    if not os.path.exists(pandoc.core.PANDOC_PATH):
        raise Exception("Pandoc not available")

    doc = pandoc.Document()
    doc.markdown = open("README.md").read()
    return doc.rst
示例#10
0
def run():
    pandoc.core.PANDOC_PATH = '/usr/local/bin/pandoc'

    doc = pandoc.Document()
    doc.markdown = open('README.md').read()
    f = open('README.rst', 'w+')
    f.write(doc.rst)
    f.close()
示例#11
0
def get_description():
    with open('README.md') as f:
        desc = f.read()
    short = desc.split('===\n')[1].strip().split('\n')[0]
    if pandoc:
        doc = pandoc.Document()
        doc.markdown = desc.encode('utf-8')
        desc = doc.rst.decode('utf-8')
    return short, desc
示例#12
0
def readme():
    try:
        import pandoc
    except ImportError:
        return ''
    doc = pandoc.Document()
    with open("README.md") as f:
        doc.markdown_github = f.read()
        return doc.rst
示例#13
0
文件: setup.py 项目: pprett/zipline
def readme_as_rest():
    """
    Converts the README.md file to ReST, since PyPI uses ReST for formatting,
    This allows to have one canonical README file, being the README.md
    """
    doc = pandoc.Document()
    with open('README.md').read() as markdown_source:
        doc.markdown = markdown_source
    return doc.rst
示例#14
0
def md_to_html(md):
    doc = pandoc.Document()
    doc.add_argument('mathjax')
    doc.add_argument('ascii')
    doc.add_argument('smart')
    doc.bib(BIBFILE)
    doc.csl(CSLFILE)
    doc.add_argument('indented-code-classes=prettyprint,linenums:1')
    doc.markdown = md
    return unicode(doc.html)
示例#15
0
    def get_week_as_html(date=None):
        content = p.get_week(date_=date)
        doc = pandoc.Document()
        doc.markdown = content
        content = str(doc.html)

        week_string = get_week_string(date=date)
        edit_link = "/%s/edit" % week_string

        return content, edit_link
示例#16
0
文件: app.py 项目: edavis/Ludwig
def main(location):
    doc = pandoc.Document()
    doc.org = open('states.org').read()
    json_obj = json.loads(doc.json)

    index = find_node_index(json_obj, location)
    if index is None:
        return ('HTTP 404 -- Could not find any node at that location.', 404)

    return build_node_content(json_obj, index)
示例#17
0
    def reload(self, dummy=True):
        "Reload the file from disk"
        if self.path.endswith('.jpg') or self.path.endswith(
                '.svg') or self.path.endswith('.png') or self.path.endswith(
                    '.jpeg'):
            self.edit.setUrl(QUrl("file://" + self.path))
            self.edit.page().setContentEditable(False)
            return

        if os.path.isfile(self.path):
            with open(self.path, "rb") as f:
                s = f.read()
            #Be compatible with files made on a certain android text editor that puts those bytes there sometimes.
            if s.startswith(b"\xff\xfe"):
                s = s[2:]
                self.pre_bytes = b"\xff\xfe"
            elif s.startswith(b"\xfe\xff"):
                s = s[2:]
                self.pre_bytes = b"\xfe\xff"
            elif s.startswith(b"\xef\xbb\xbf"):
                s = s[3:]
                self.pre_bytes = b"\xef\xbb\xbf"
            else:
                self.pre_bytes = b''  #now we are going to use pandoc to convert to html
            doc = pandoc.Document()

            #Figure out the input format. We back things up and archive them by appenting a Timestamp
            #to the end or else a ~. That function strips both of those things.
            if util.striptrailingnumbers(self.path).endswith(".html"):
                doc.html = s
                self.edit.page().setContentEditable(False)

            #The special html.ro lets us have read only HTML used for handy calculators and stuff.
            elif util.striptrailingnumbers(self.path).endswith(".html.ro"):
                doc.html = s
                self.edit.page().setContentEditable(False)

            elif util.striptrailingnumbers(self.path).endswith(".md"):
                doc.markdown_github = s

            elif util.striptrailingnumbers(self.path).endswith(".rst"):
                doc.rst = s
            else:
                raise RuntimeError("Bad filetype")
            html = doc.html.decode("utf-8")

            #Add the CSS file before the HTML
            d = "<style>" + styles.style + "</style>"
            self.header_size = len(d)
            d += html

            self.edit.setHtml(
                d,
                QUrl("file://" + self.path) if self.path else QUrl("file:///"))
示例#18
0
文件: app.py 项目: edavis/Ludwig
def index():
    doc = pandoc.Document()
    doc.org = open('states.org').read()
    json_obj = json.loads(doc.json)

    # Use _index, if possible
    index = find_node_index(json_obj, '_index')
    if index is not None:
        return build_node_content(json_obj, index)

    return build_index(json_obj)
示例#19
0
def include_readme():
    try:
        import pandoc
    except ImportError:
        return ''
    pandoc.core.PANDOC_PATH = find_executable('pandoc')
    readme_file = os.path.join(os.path.dirname(__file__), 'README.md')
    doc = pandoc.Document()
    with open(readme_file, 'r') as rf:
        doc.markdown = rf.read()
        return doc.rst
示例#20
0
文件: server.py 项目: csu/progress
    def get_week_as_html(date=None):
        content = p.get_week(date_=date)

        if content:
            doc = pandoc.Document()
            doc.markdown = content
            content = str(doc.html)
        else:
            content = ""

        return content, get_edit_link(date)
示例#21
0
def normalize_to_md(readme_contents, file_name):
    # normalize to Github flavored markdown
    doc = pandoc.Document()
    if file_name.endswith('.rst'):
        doc.rst = readme_contents.encode('utf-8')
    elif file_name.endswith('.textile'):
        doc.textile = readme_contents.encode('utf-8')
    else:
        # doc.gfm = readme_contents.encode('utf-8')
        return normalize_md_headings(readme_contents)
    return doc.gfm.decode("utf-8")
示例#22
0
def readMD(fname):
    # Utility function to read the README file.
    full_fname = os.path.join(os.path.dirname(__file__), fname)
    if 'PANDOC_PATH' in os.environ:
        import pandoc
        pandoc.core.PANDOC_PATH = os.environ['PANDOC_PATH']
        doc = pandoc.Document()
        with open(full_fname) as fhandle:
            doc.markdown = fhandle.read()
        return doc.rst
    else:
        return read(fname)
    def generateHelpContent(self):
        """
        I could make this a read in an markdown file and fill the markdown file with 
        """
        doc = pandoc.Document()
        doc.markdown = open("helpPageContent.md", 'rb').read()

        retval = DEFAULT_VISIBLE_CONTAINER()
        retval.style['margin-left'] = "2%"
        retval.style['margin-right'] = "2%"
        retval.add_child('text', doc.html.decode('utf-8'))

        return retval
示例#24
0
def get_long_description():
    readme_file = 'README.md'
    if not os.path.isfile(readme_file):
        return ''
    # Try to transform the README from Markdown to reStructuredText.
    try:
        import pandoc
        pandoc.core.PANDOC_PATH = 'pandoc'
        doc = pandoc.Document()
        doc.markdown = open(readme_file).read()
        description = doc.rst
    except Exception:
        description = open(readme_file).read()
    return description
示例#25
0
def markdown2rst(md):
    """Convert markdown to rst format using pandoc. No other processing."""
    # import here, because outside it might not used
    try:
        import pandoc
    except ImportError as e:
        raise
    else:
        pandoc.PANDOC_PATH = 'pandoc'  # until pyandoc gets updated

    doc = pandoc.Document()
    doc.markdown_github = md
    rst = doc.rst

    return rst
示例#26
0
class Config:
    MD_COMP_URL = f"https://twcloud.lsst.org:8111/osmc/resources/{{res}}/elements/{{comp}}"
    PANDOC_TYPE = None
    DOC = pandoc.Document()
    OUTPUT_FORMAT = None
    CACHED_GIT_REPOS = {}
    # to store here git trees when MD Section is ongoing to avoid rate limit problem?
    CACHED_GIT_TREES = []
    MODE_PREFIX = None
    TIMEZONE = "US/Pacific"
    TEMPLATE_LANGUAGE = "latex"
    TEMPLATE_DIRECTORY = os.curdir

    # Regexes for LSST things
    DOC_NAMES = ['LDM', 'LSE', 'DMTN', 'DMTR', 'TSS', 'LPM']
    doc_pattern_text = r"\b(" + "|".join(DOC_NAMES) + r")(-\d+)([\s\.])"
    DOCUSHARE_DOC_PATTERN = re.compile(doc_pattern_text)
    milestone_pattern_text = r"\b(" + "|".join(DOC_NAMES) + r")(-\d+-\d+)([\s\.])"
    SUBSYSTEM_YML_FILE = "subsystem.yaml"
示例#27
0
    def save(self, name=None):
        name = name or self.path
        #Readonly html file support
        if name.endswith(".ro"):
            return
        if name.endswith(".html"):
            return
        "Save the file if it needs saving"
        if not self.edit.page().isModified():
            return

        #Back Up File
        buf = None
        #If the file exists, copy it to file~ first. If that exists, copy it to file4857475928345
        if os.path.exists(name):
            if not os.path.exists(name + "~"):
                buf = (name + "~")
                shutil.copy(name, name + "~")
            else:
                buf = name + str(time.time())
                shutil.copy(name, buf)

        #Again, pandoc to convert to the proper format
        doc = pandoc.Document()
        h = downloadAllImages(self.edit.page().mainFrame().toHtml(), name)
        doc.html = destyle_html(h).encode("utf-8")

        if util.striptrailingnumbers(name).endswith(".md"):
            with open(name, "wb") as f:
                f.write(self.pre_bytes + doc.markdown_github)

        if util.striptrailingnumbers(name).endswith(".rst"):
            with open(name, "wb") as f:
                f.write(self.pre_bytes + doc.rst)

        if buf and os.path.isfile(buf):
            os.remove(buf)

        #Reload to mark as saved, before the filesystem watcher ca get to it.
        self.reload()
示例#28
0
def get_long_description():
    with open('./README.md') as f:
        readme = f.read()

    try:
        import pandoc
    except ImportError:
        return readme

    path = None
    for p in ('/usr/local/bin/pandoc', '/usr/bin/pandoc'):
        if os.path.exists(p):
            path = p

    if path is None:
        print 'pandoc not found'
        return readme

    pandoc.core.PANDOC_PATH = path
    doc = pandoc.Document()
    doc.markdown = readme
    return doc.rst
示例#29
0
def get_summary_md(wikipedia_slug: str, wikipedia_section: str):
    response = requests.get(
        'https://en.wikipedia.org/w/api.php',
        params={
            'action': 'query',
            'format': 'json',
            'titles': wikipedia_slug,
            'prop': 'extracts',
            'explaintext': True,
        },
    ).json()
    text = next(iter(response['query']['pages'].values()))['extract']
    wikicode = mwparserfromhell.parse(text)
    section = wikicode.get_sections(
        levels=[2],
        matches=wikipedia_section,
        include_headings=False,
    )[0].strip()

    doc = pandoc.Document()
    doc.mediawiki = section.encode('utf-8')
    return doc.markdown.decode()
示例#30
0
文件: main.py 项目: iPieter/peacock
def build_post(path, post, destination_file, config_data):

    post_config = config_data
    post_config.update(post)

    if "index.md" in post["files"]:
        logging.debug("Rendering markdown file for this post.")
        with open(os.path.join(post["path"], "index.md"), mode="r") as f:
            doc = pandoc.Document()
            doc.markdown_github = f.read().encode("utf-8")
            post_config["text"] = doc.html.decode()
            post_config["html"] = ""
    elif "index.html" in post["files"]:
        logging.debug("Using html file for this post.")
        with open(os.path.join(post["path"], "index.html"), mode="r") as f:
            post_config["html"] = f.read()
            post_config["text"] = ""

    rendered = parse_file(os.path.join(path, "_post.html"), config_data)

    with open(os.path.join(destination_file), mode="w") as fout:
        fout.write(rendered)