Esempio n. 1
0
def main():
    link_mapping_pairs = parse_link_mapping(
        codecs.open("sg/policy-link-mapping.txt", "r",
                    encoding="utf-8").read())
    template = codecs.open("policy-template.html", "r",
                           encoding="utf-8").read()
    for resource, link in link_mapping_pairs:
        if link.startswith("https:"):
            continue

        policy_markdown = codecs.open("sg" + resource[1:].replace("%20", " "),
                                      "r",
                                      encoding="utf-8").read()

        (title, policy_markdown) = markdown_title(policy_markdown)
        preprocessed_policy_markdown = preprocess_markdown(
            policy_markdown, link_mapping_pairs)

        policy_html = markdown.markdown(
            preprocessed_policy_markdown,
            extensions=[PartialGithubFlavoredMarkdownExtension()])

        final_policy_html = template.replace("@POLICY_GOES_HERE@", policy_html)
        final_policy_html = final_policy_html.replace("@TITLE_GOES_HERE@",
                                                      title)

        codecs.open("whatwg.org/" + link, "w",
                    encoding="utf-8").write(final_policy_html)
    def _show_help(self):
        dialog = QtGui.QDialog(self.central_widget)
        dialog.setWindowTitle("Help")

        with open(self._help_file, "r") as readme_file:
            readme_text = readme_file.read()

        md = markdown.Markdown(extensions=[
            PartialGithubFlavoredMarkdownExtension(), "markdown.extensions.toc"
        ])
        readme_text = re.sub(r'(\[!.*)', '[TOC]', readme_text)
        html = md.convert(readme_text)

        textBrowser = QtGui.QTextBrowser()
        textBrowser.setSource(QtCore.QUrl(self._help_file))
        textBrowser.setHtml(html)
        textBrowser.setOpenLinks(False)
        textBrowser.anchorClicked.connect(
            partial(self._click_help, textBrowser))

        dialogButtons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
        dialogButtons.accepted.connect(dialog.accept)

        dialogLayout = QtGui.QVBoxLayout()
        dialogLayout.addWidget(textBrowser)
        dialogLayout.addWidget(dialogButtons)

        dialog.setLayout(dialogLayout)
        windowSize = self.central_widget.size()
        dialog.setMinimumHeight(windowSize.height() / 2)
        dialog.setMinimumWidth(windowSize.width() / 2)

        dialog.exec_()
Esempio n. 3
0
def main():
    (policy_file, template_file, link_mapping_file) = parse_arguments()
    policy_markdown = policy_file.read().decode('utf-8')
    template = template_file.read().decode('utf-8')
    link_mapping = link_mapping_file.read().decode('utf-8')

    (title, policy_markdown) = markdown_title(policy_markdown)
    preprocessed_policy_markdown = preprocess_markdown(policy_markdown, link_mapping)

    policy_html = markdown.markdown(preprocessed_policy_markdown, extensions=[PartialGithubFlavoredMarkdownExtension()])

    final_policy_html = template.replace("@POLICY_GOES_HERE@", policy_html)
    final_policy_html = final_policy_html.replace("@TITLE_GOES_HERE@", title)

    print(final_policy_html.encode('utf-8'))
Esempio n. 4
0
from config import *
from util import *
from os import system
import re
import markdown
from mdx_partial_gfm import PartialGithubFlavoredMarkdownExtension
from bs4 import BeautifulSoup as soup

gfm = markdown.Markdown(extensions=[PartialGithubFlavoredMarkdownExtension()])

system("rm -rf in")
system("mkdir in")

for post in POSTS:
    postc = POSTS[post]
    if not postc.get("published", False): continue
    title = postc.get("title")
    pslug = slug(postc)
    first_paragraph = soup(gfm.convert(postc.content),
                           "html.parser").find("p").text.replace("\n",
                                                                 " ").replace(
                                                                     "  ", " ")
    excerpt = truncate(first_paragraph, postc.get("excerpt_length"))
    with open("in/{}.html".format(pslug), "w") as f:
        f.write(
            "<!-- attrib title: {} -->\n<!-- attrib description: {}-->\n<!-- attrib template: post -->\n<!-- attrib sitename: {} -->\n\n"
            .format(title, excerpt, BLOG_NAME))
        f.write("<h1>{} (published {})</h1>\n\n".format(
            title, postc.get("pubdate", "1970-01-01")))
        f.write(
            gfm.convert(postc.content).replace(
Esempio n. 5
0
    def extendMarkdown(self, md, md_globals):
        PartialGithubFlavoredMarkdownExtension.extendMarkdown(self, md, md_globals)

        Nl2BrExtension().extendMarkdown(md, md_globals)
Esempio n. 6
0
import markdown

from mdx_partial_gfm import PartialGithubFlavoredMarkdownExtension
from jujubundlelib import references
from theblues.charmstore import CharmStore
from theblues.errors import EntityNotFound, ServerError
from theblues.terms import Terms


cs = CharmStore(timeout=5)
terms = Terms("https://api.jujucharms.com/terms/")

SEARCH_LIMIT = 400

markdown = markdown.Markdown(
    extensions=[PartialGithubFlavoredMarkdownExtension()]
)


def search_entities(
    query,
    entity_type=None,
    tags=None,
    sort=None,
    series=None,
    owner=None,
    promulgated_only=None,
):
    includes = [
        "charm-metadata",
        "bundle-metadata",