Giter Club home page Giter Club logo

Comments (8)

mika-cn avatar mika-cn commented on July 17, 2024

What Block links do in HTML is just enlarge the clickable area. I think we can safely convert them into Markdown with easy understand format.

Here's my thoughts about these convertions:

Image block links

HTML:

<a href="/link.html">
  <div>
    <img src="a-picture.png" alt="alt-text" title="title-text">
  <div>
</a>

To convert these image block links, we can just put the link below the image, like this:

Markdown:

![alt-text](a-picture.png "title-text")

[link-text](/link.html)

Note that we padding the whole content with two line breakers (the markdown render of Github may ignore these lines, So you might not seeing them) so that it won't become a inline image. And about the "link-text" we can use either alter-text or title-text if it's exist. Or a hard-coded one like: "picture link" if none of them is exist.

As markdown supports image links, we can of cause convert it to common markdown format, like [![alt-text](a-picture.png "title-text")](/link.html).in this case.

block links of multiple lines of text

HTML:

<a href="/link.html">
  <div>
    <p>line A</p>
    <p>line B</p>
    <p>line c</p>
  </div>
</a>

This case is very common in some clickable cards on web page, such as: online shopping item cards, contact info cards etc. We can't simply put the link below the text content in this case. Instead, we can wrap these lines with two links, one at the beginning, one at the end. link this:

Markdown:

[↓↓↓](/link.html)

line A

line B

line C

[↑↑↑](/link.html)

Note that we also padding the whole content with two link breakers, and we using three downward arrows and three upward arrows as link text.

other block links?

  • block links of table (I haven't seen one yet, we can handle it same as image block links)
  • others? (I have not ideas)

What's on your mind? please comment below.

from maoxian-web-clipper.

mika-cn avatar mika-cn commented on July 17, 2024

@Golddouble About the block links of multiple lines of text, discuss here.

from maoxian-web-clipper.

Golddouble avatar Golddouble commented on July 17, 2024

Before I say anything about "block links of multiple lines of text" I would like to ask, how you managed to convert the "image block links" into clean Markdown.

I think of it like this:

  1. The "Web Clipper" extracts the HTML code that the user has selected with the "Web Clipper" in the browser.
  2. With the extract "Web Clipper creates now a HTML file
  3. The code of the "Web Clipper" searches the HTML file for "image block links" by searching for ...
<a href="/link.html">
  <div>
    <img src="a-picture.png" alt="alt-text" title="title-text">
  <div>
</a>
  1. In the HTML file, the "Web Clipper" somehow marks the found places.
  2. The "Web Clipper" lets the HTML file with the markings pass through the turndown converter. This means that the marks from point 4) must not affect the conversion and must still be present after the conversion process.
  3. Now the Markdown file is in the raw version.
  4. The "Web Clipper" converts the previously marked "image block links" in such a way that they can be displayed as the user expects.

Is that how it works?

If so, couldn't you now simply also mark ...

<a href="/link.html">
  <div>
    <p>line A</p>
    <p>line B</p>
    <p>line c</p>
  </div>
</a>

... and after convert them in a good looking Markdown file?

from maoxian-web-clipper.

mika-cn avatar mika-cn commented on July 17, 2024

Actually, we modify the html before pass it to Turndown. It's kind of like preprocess the html. We decide what the final format is, then modify the html so it'll not contains block links and feed it to Turndown to get the result.

It shouldn't be hard to write the code, but hard to figure out all situations. And we need to decide what markdown format each situation will be converted to.

I met a new case today:

<a href="/link.html>
  <h2>a section header</h2>
</a>

and it get converted to:

[

## a section header

](/link.html)

I think it should be converted to:

## [a section header](/link.html)

but I don't remember that markdown can support header links, and I tried it on some online markdown editors, they did know how to render this markdown.

from maoxian-web-clipper.

mika-cn avatar mika-cn commented on July 17, 2024

I've published a new version(v0.4.39) that contains preprocess of block links. It should handle the cases that mentioned above. It's not perfect, we will enhance it when we encounter new problems.

from maoxian-web-clipper.

Golddouble avatar Golddouble commented on July 17, 2024

Thank you. I will let you know, when I encounter new problems.

## [a section header](/link.html)
but I don't remember that markdown can support header links, and I tried it on some online markdown editors, they did know how to render this markdown.

I use markdown in Obsidian. And Obsidian also renders ## . So no problem for Obsidian either.

from maoxian-web-clipper.

Leilei332 avatar Leilei332 commented on July 17, 2024

In some cases, inline links may be regarded as block links because of its style. Like this:

图片

This inline link was regarded as a block link because it has an SVG image.

图片

from maoxian-web-clipper.

mika-cn avatar mika-cn commented on July 17, 2024

@Leilei332

This inline link was regarded as a block link because it has an SVG image.

I can reproduce this problem, will fix it in next version.

from maoxian-web-clipper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.