Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I included the instruction to use regular expressions to do the conversion to ANSI.

The viber coders (who I referred to in my comment) aren't giving implementation tips.

What did it give you before you put an implementation tip into your prompt?

=======

FWIW, if you're at all interested, here's my implementation:

    def markdown_ansi_code_subst(mdstr: str, src_pattern: str, replacement_start: str, replacement_end: str) -> str:
        while src_pattern in mdstr:
            mdstr = mdstr.replace(src_pattern, replacement_start, 1)
            mdstr = mdstr.replace(src_pattern, replacement_end, 1)
        return mdstr
The caller supplies the pattern (`*` for italic, `**` for bold, etc) and a start/end replacement. As you can imagine, I store all of that in a static lookup table.

I feel this is more readable than regexes.*



The prompt was:

> Give me a Python function that takes a string holding text in Markdown markup syntax and that uses regular expressions to replace any Markdown markup codes for bold, italics and underline with their ANSI equivalent.

BTW, your solution will produce bad output. Markdown's "bold" etc markup comes in pairs of markers and your simple replacement will match singlets.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: