~fabrixxm/confy-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] Convert markdown links to html hyperlinks

Details
Message ID
<20220720134257.32505-1-devrtz@fortysixandtwo.eu>
DKIM signature
missing
Download raw message
Patch: +6 -2
The following is an example of the regex:

>>> orig='some text about [debian](https://debian.org "woohoo") yay!'
>>> re.sub("\[([^]]+?)\]\(([^)\s]+?).*?\)", r'<a href="\2">\1</a>', orig)
'some text about <a href="h">debian</a> yay!'

Closes #19
---
 src/pages.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/pages.py b/src/pages.py
index be772f5..46dce9e 100644
--- a/src/pages.py
+++ b/src/pages.py
@@ -37,6 +37,10 @@ from .config import APP_NAME, APP_ID, APP_VERSION, FMT_DAY_LIST
from . import models


def _convert_markdown_links(text):
    """converts markdown links to html hyperlinks"""
    return re.sub("\[([^\]]+?)\]\(([^\)]+?).*?\)", r'<a href="\2">\1</a>', text)

def _clean_markup(text):
    """remove unsupported markup from text to use in label"""
    text = text.replace("<p>", "").replace("</p>", "\n\n")
@@ -481,12 +485,12 @@ class EventDetailPage(BasePage):
        # By now just filter out, but a more in-depth look should be taken
        if obj.abstract is not None and obj.abstract != "" and obj.abstract != "None":
            label = Gtk.Label(**LBL_PROPS)
            label.set_markup(_clean_markup(obj.abstract))
            label.set_markup(_clean_markup(_convert_markdown_links(obj.abstract)))
            box.pack_start(label, False, False, 16)

        if obj.description is not None and obj.description != "" and obj.description != "None":
            label = Gtk.Label(**LBL_PROPS)
            label.set_markup(_clean_markup(obj.description))
            label.set_markup(_clean_markup(_convert_markdown_links(obj.description)))
            box.pack_start(label, False, False, 16)

        ## links
-- 
2.35.1
Details
Message ID
<85113bb4863452dc433540443920e7e912fe20ec.camel@fortysixandtwo.eu>
In-Reply-To
<20220720134257.32505-1-devrtz@fortysixandtwo.eu> (view parent)
DKIM signature
missing
Download raw message
Nvm,

the links are actually broken currently

expect a v2 soon.

On Wed, 2022-07-20 at 15:42 +0200, Evangelos Ribeiro Tzaras wrote:
> The following is an example of the regex:
> 
> > > > orig='some text about [debian](https://debian.org "woohoo")
> > > > yay!'
> > > > re.sub("\[([^]]+?)\]\(([^)\s]+?).*?\)", r'<a href="\2">\1</a>',
> > > > orig)
> 'some text about <a href="h">debian</a> yay!'
> 
> Closes #19
> ---
>  src/pages.py | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/src/pages.py b/src/pages.py
> index be772f5..46dce9e 100644
> --- a/src/pages.py
> +++ b/src/pages.py
> @@ -37,6 +37,10 @@ from .config import APP_NAME, APP_ID, APP_VERSION,
> FMT_DAY_LIST
>  from . import models
>  
>  
> +def _convert_markdown_links(text):
> +    """converts markdown links to html hyperlinks"""
> +    return re.sub("\[([^\]]+?)\]\(([^\)]+?).*?\)", r'<a
> href="\2">\1</a>', text)
> +
>  def _clean_markup(text):
>      """remove unsupported markup from text to use in label"""
>      text = text.replace("<p>", "").replace("</p>", "\n\n")
> @@ -481,12 +485,12 @@ class EventDetailPage(BasePage):
>          # By now just filter out, but a more in-depth look should be
> taken
>          if obj.abstract is not None and obj.abstract != "" and
> obj.abstract != "None":
>              label = Gtk.Label(**LBL_PROPS)
> -            label.set_markup(_clean_markup(obj.abstract))
> +           
> label.set_markup(_clean_markup(_convert_markdown_links(obj.abstract))
> )
>              box.pack_start(label, False, False, 16)
>  
>          if obj.description is not None and obj.description != "" and
> obj.description != "None":
>              label = Gtk.Label(**LBL_PROPS)
> -            label.set_markup(_clean_markup(obj.description))
> +           
> label.set_markup(_clean_markup(_convert_markdown_links(obj.descriptio
> n)))
>              box.pack_start(label, False, False, 16)
>  
>          ## links

-- 
Cheers,

Evangelos
PGP: B938 6554 B7DD 266B CB8E 29A9 90F0 C9B1 8A6B 4A19
Reply to thread Export thread (mbox)