git @ Cat's Eye Technologies Dipple / master python / unchrysoberyl-markdown.py
master

Tree @master (Download .tar.gz)

unchrysoberyl-markdown.py @masterraw · history · blame

# SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
# For more information, please refer to <https://unlicense.org/>
# SPDX-License-Identifier: Unlicense

import sys
import re
from urllib.parse import quote


def unchrysoberyl(contents):

    def linker(match):
        text = match.group(1)
        segments = text.split('|')
        if len(segments) == 1:
            phrase = segments[0]
            link = "http://catseye.tc/node/{}".format(quote(phrase))
        elif len(segments) == 2:
            phrase = segments[0]
            link = "http://catseye.tc/node/{}".format(quote(segments[1]))
        else:
            raise NotImplementedError
        return '[{}]({})'.format(phrase, link)

    return re.sub(r'\[\[(.*?)\]\]', linker, contents)


print(unchrysoberyl(sys.stdin.read()))