コード例 #1
0
def markdown_doc():
    return md.MarkdownDocument(
        textwrap.dedent("""
        # Title

        This is an intro paragraph.

        ## Sub 1

        Stuff and things, things and stuff.

        ### Drilling down

        This had a deeper item.

        ```python
        # This is a code example.
        ```

        ### Still drilling

        Drill drill drill

        ## Sub 2

        Weeeee
    """).strip())
コード例 #2
0
    def content(self) -> md.MarkdownDocument:
        # Render the content template into the actual content.
        answer = next(iter(self.templates.values())).render(
            aip=self,
            site=self.site,
        )

        # TEMPORARY: In the interest of having two discrete migrations,
        # rewrite the old link style to the new one.
        answer = re.sub(
            r'\.?\./0([\d]{1,3})\.md',
            lambda m: f'{self.site.relative_uri}/{int(m.groups()[0]):d}',
            answer,
        )

        # Hotlink AIP references.
        # We only hotlink the generally-applicable ones for now until we have
        # a prefix system implemented.
        answer = re.sub(
            r'\b(?<!\[)AIP-([\d]{1,3})\b',  # AIP-###, but not after a `[`.
            fr'[AIP-\1]({self.site.relative_uri}/\1)',
            answer,
        )

        # Append the changelog if there is one.
        if self.changelog:
            answer += '\n\n## Changelog\n\n'
            for cl in sorted(self.changelog):
                answer += f'- **{cl.date}:** {cl.message}\n'

        # Return the document.
        return md.MarkdownDocument(answer)
コード例 #3
0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import jinja2
import jinja2.ext
import jinja2.nodes

from aip_site import md

TEMPLATE_DIR = os.path.realpath(
    os.path.join(os.path.dirname(__file__), '..', 'support', 'templates'), )

# "Standard" jinja2 environment that loads from the filesystem.
jinja_env = jinja2.Environment(
    loader=jinja2.FileSystemLoader(searchpath=TEMPLATE_DIR),
    undefined=jinja2.StrictUndefined,
)
jinja_env.filters['markdown'] = lambda s: md.MarkdownDocument(s).html