Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra for generating link preview #488

Closed
BoPeng opened this issue Dec 2, 2022 · 5 comments
Closed

Extra for generating link preview #488

BoPeng opened this issue Dec 2, 2022 · 5 comments
Labels
Feature Feature request

Comments

@BoPeng
Copy link

BoPeng commented Dec 2, 2022

Instead of using a node.js based solution (e.g. link-preview-generator), I am wondering how I can generate link preview during the processing of markdown. There appears to modules (e.g. linkpreview) that perform the actual uplifting so maybe it is not too difficult to add an extra for this.

@BoPeng
Copy link
Author

BoPeng commented Dec 4, 2022

I notice that extras are not implemented as separate modules, so this has to be incorporated into lib/markdown2.py. Does this look like a decent feature to justify the acceptance of a PR?

@nicholasserra
Copy link
Collaborator

Where do you see this preview information being stored?

There's also pre and post process hooks in the codebase if you wanna import and then subclass the module, then add your own data as you see fit.

Also check out https://github.com/michaelhelmick/lassie/

@nicholasserra nicholasserra added the Feature Feature request label Dec 5, 2022
@BoPeng
Copy link
Author

BoPeng commented Dec 5, 2022

Thanks for pointing me to lassie. Basically I want to process markdown (or generated HTML content) and add previews. It has not been decided yet but I think I want to convert paragraphs with a single link to a block with image, title etc. Something like

I see

https://www.cnn.com/2022/12/04/us/power-outage-moore-county-criminal-investigation/index.html

today

will be converted to something like

I see

[ image ] Title
[ image [ author, date, etc

today

@nicholasserra
Copy link
Collaborator

Got it. Sounds interesting. But also very specific. Would probably be a worthwhile extra assuming it was built out to allow customization. Not sure if that's worth it for you to work on, but if it were to go down that path, it would probably be accepted.

@BoPeng
Copy link
Author

BoPeng commented Dec 5, 2022

Sounds interesting. But also very specific ... built out to allow customization.

I am using python-markdown2 to convert user input into HTML in the backend of a website. I am calling markdown2 like

markdown(my_text, extras= { ...})

so I essentially need a hook like

def link_to_preview(link):
    return html-based-on-lassie

markdown(my_text, extras={
    'link_preview': {
        'select': 'single-paragraph',
        'processor': link_to_preview
    }
 }

So that markdown2 will look for particular types of links (in this case single-link-paragraphs) and replace them with results from a user-provided processor.

@BoPeng BoPeng closed this as completed May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Feature request
Projects
None yet
Development

No branches or pull requests

2 participants