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

Faster link highlighting with more types supported #188

Merged
merged 6 commits into from
Aug 24, 2023

Conversation

tim-gromeyer
Copy link
Contributor

@tim-gromeyer tim-gromeyer commented Aug 20, 2023

  1. Faster link highlighting
  2. More link types supported
  3. Don't highlight HTML tags with a . in it (not true anymore, since it wes requested to support files...)

@@ -2051,7 +2026,7 @@ void MarkdownHighlighter::highlightInlineRules(const QString &text) {
*/
int MarkdownHighlighter::highlightInlineSpans(const QString &text,
int currentPos, const QChar c) {
//clear code span ranges for this block
// clear code span ranges for this block
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing changed below this spot, except the formatting. The next change is in the next file

@tim-gromeyer tim-gromeyer marked this pull request as draft August 20, 2023 23:14
@tim-gromeyer
Copy link
Contributor Author

I noticed something: It highlights HTML tags as links, I need to fix this

@pbek
Copy link
Owner

pbek commented Aug 21, 2023

Thank you for your concern.
You ripped a lot of code out. It's hard to tell what implications that would have.

@Waqar144, opinions?

@tim-gromeyer
Copy link
Contributor Author

You ripped a lot of code out. It's hard to tell what implications that would have.

Yeah, I ripped the old code out which used regular expressions. It was just to unreliable so I replaced it

@tim-gromeyer tim-gromeyer force-pushed the more-robust-link-highlighting branch from 868e3eb to 8d1c397 Compare August 21, 2023 09:04
@tim-gromeyer tim-gromeyer marked this pull request as ready for review August 21, 2023 09:04
@tim-gromeyer
Copy link
Contributor Author

It is fixed now!

@tim-gromeyer
Copy link
Contributor Author

You ripped a lot of code out. It's hard to tell what implications that would have.

You can test it by using the following file (https://raw.githubusercontent.com/tim-gromeyer/html2md/main/tests/links.md) to check the highlighting. It should match the behavior as it did before.

You can copy the content of the linked file and try out the old behavior here (https://tim-gromeyer.github.io/MarkdownEdit/markdownedit.html). Then, compare it to a locally built version with this PR integrated.

@Waqar144
Copy link
Contributor

Waqar144 commented Aug 22, 2023

And sorry... my IDE changed a bit of formatting in some lines... but no feature changes

Yes, but it makes reviewing harder than it needs to be as one has to go through changes that are meaningless. Thus I would suggest you to remove the formatting changes, or at least put them in a separate commit, then rebase the actual feature changes on top. The way it currently is, it is hard to see what is going on.

It is also bad for git blame history.

@Waqar144
Copy link
Contributor

Code wise things look okay I think. The new link highlighting code probably won't be able to handle complex link cases but those don't matter usually and I haven't tested to be sure.

@pbek
Copy link
Owner

pbek commented Aug 22, 2023

I'd also rather like to have whitespace changes in a different PR...

@tim-gromeyer
Copy link
Contributor Author

Allright, I'll try to revert the formatting changes

@tim-gromeyer tim-gromeyer force-pushed the more-robust-link-highlighting branch from 39823a4 to 9030278 Compare August 22, 2023 12:51
@pbek
Copy link
Owner

pbek commented Aug 22, 2023

And this PR breaks lots of links...

image

<link%20destination.md>
<linkdestination.md>
[Link test](Link%20test.txt)
[Link Destination - Heading 2](Link%20Destination.md#Heading%202)
[Link test - A heading](Link%20test.md#A%20heading)

---

[Test 1](Test%201.md#Heading%201)
[# Test 1](Link%20Destination.md#Heading%201)
[# Test 2](Link%20Destination.md#Heading%202)
[# Test 3](Link%20Destination.md#Heading)
[# Test 3](Link%20Destination.md#Heading)

[# Test 4](.#A%20Heading)
[Link test](Link%20test.md#A%20Heading)
[# Test 3](Link%20Destination.md)

<Link%20Destination.md>
<Link%20Destination.md>

asdas www.github.com asdasd
www.github.com
https://www.github.com


- [Rename test](folder/Rename%20test3c.md)

- [Rename test](Rename%20test3b.md)
- [Note with one bracket](Note%20with%20one%20bracket%5D.md)
- [Note with one bracket](Note%20with one bracket].md)
- [Note with one bracket](Note%20with&#32;one bracket].md)

@tim-gromeyer tim-gromeyer force-pushed the more-robust-link-highlighting branch from 9030278 to 231a188 Compare August 22, 2023 13:03
@tim-gromeyer
Copy link
Contributor Author

tim-gromeyer commented Aug 22, 2023

For the links enclosed in angle brackets (<>) it is on purpose. Before it also highlighted HTML tags with a dot (.) in it. For example <script src="script.js">. Just put file:// before it and it will work

And for the greyed links... I didn't saw it. You couldn't really see it with dark mode

What highlighter state _format[HighlighterState] does it use?

Edit: It also fixes things like this:

## Images with References

[![Forest][forest-image]][forest-link]

[forest-image]: https://www.example.com/images/forest.jpg
[forest-link]: https://www.example.com/nature/forest

@tim-gromeyer tim-gromeyer force-pushed the more-robust-link-highlighting branch from e93567c to c18ab90 Compare August 22, 2023 15:24
@tim-gromeyer
Copy link
Contributor Author

@pbek, can you test it again, please? It should be fixed now

@tim-gromeyer tim-gromeyer force-pushed the more-robust-link-highlighting branch from c18ab90 to b597cbf Compare August 22, 2023 18:39
@tim-gromeyer tim-gromeyer force-pushed the more-robust-link-highlighting branch from b597cbf to 53c4c59 Compare August 23, 2023 07:38
@pbek
Copy link
Owner

pbek commented Aug 23, 2023

Those still don't work:

## PR 188

- <note://QOwnNotes_Todo>
- <link%20destination.md>
- <linkdestination.md>
- <attachments/1672212884.pdf>
- note://Note_2018_06_26T22_11_10
- <../p11.md>

@pbek
Copy link
Owner

pbek commented Aug 23, 2023

Link highlighting doesn't work some times.

Can you please give some examples when it doesn't work?
And can you please explain why your changes are more robust?

I'm still very unhappy to lose all the documentation on what cases of links the regular expressions cover...

@tim-gromeyer
Copy link
Contributor Author

Those still don't work:

## PR 188

- <note://QOwnNotes_Todo>
- <link%20destination.md>
- <linkdestination.md>
- <attachments/1672212884.pdf>
- note://Note_2018_06_26T22_11_10
- <../p11.md>

The files don't work on purpose. Use file:// and it will work. The files caused some problems, they sometimes highlighted HTML tags if they contained a dot

And for note://, I can add support for it by simply adding note:// to this list

But 1 Question: Should note:// always be highlighted or just when it's in ankled brackets (<>)

@tim-gromeyer
Copy link
Contributor Author

tim-gromeyer commented Aug 23, 2023

Can you please give some examples when it doesn't work?

Images with references... don't work with this PR either. It's just way too complex

And can you please explain why your changes are more robust?

  1. I encountered an issue but found a solution... (Original reason)
  2. This change should result in improved performance. (I once used regex in a C++ library, and after removing it, the tests were 60% faster, even though another library was used twice to perform conversions before and after...)
  3. Adds support for more types of links (see the isLink function)
  4. Fixes some instances of HTML tags being highlighted

I'm still very unhappy about losing all the documentation regarding the cases of links that the regular expressions cover...

I can add more documentation if you would like; it's a pretty simple task

@Waqar144
Copy link
Contributor

Those still don't work:

  • note://QOwnNotes_Todo
  • <link%20destination.md>
  • <linkdestination.md>
  • <attachments/1672212884.pdf>
  • note://Note_2018_06_26T22_11_10
  • <../p11.md>

imo, Those shouldn't be handled by this library as they aren't really links I think but only something that QON considers as links. As such, QON should highlight these in it's highlighter subclass. The base class should be more generic

@pbek
Copy link
Owner

pbek commented Aug 23, 2023

imo, Those shouldn't be handled by this library as they aren't really links I think but only something that QON considers as links. As such, QON should highlight these in it's highlighter subclass. The base class should be more generic

This would be fine with me, but then someone would need to do the migration in https://github.com/pbek/QOwnNotes/blob/main/src/helpers/qownnotesmarkdownhighlighter.cpp first before I'd consider merging that PR...

@tim-gromeyer
Copy link
Contributor Author

I already added support for it here

QLatin1String("spotify:"), QLatin1String("steam:"),
QLatin1String("bitcoin:"), QLatin1String("magnet:"),
QLatin1String("ed2k://"), QLatin1String("news:"),
QLatin1String("ssh://"), QLatin1String("note://")};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note:// is supported here

@pbek
Copy link
Owner

pbek commented Aug 24, 2023

I already added support for it here

yes, but just the note:// ones...

@tim-gromeyer
Copy link
Contributor Author

I already added support for it here

yes, but just the note:// ones...

What else do you want? The files? They caused problems with some HTML tags being highlighted. They are not highlighted on purpose because of this. You can use file:// or make a list of all file extensions and check if it ends with a known one to avoid false positives with HTML tags.

@Waqar144
Copy link
Contributor

I already added support for it here

yes, but just the note:// ones...

What else do you want? The files? They caused problems with some HTML tags being highlighted. They are not highlighted on purpose because of this. You can use file:// or make a list of all file extensions and check if it ends with a known one to avoid false positives with HTML tags.

I think he means that we still need to be able to support all the kind of links that previous code did. Some links that may not be "generic" enough and are only needed to by QOwnNotes need to be supported there, so someone, must add support for them in QON before this PR can be considered for merging.

@tim-gromeyer
Copy link
Contributor Author

I think he means that we still need to be able to support all the kind of links that previous code did

It had a tendency to highlight HTML tags, but of course I'll add support for that

@tim-gromeyer tim-gromeyer changed the title More robust link highlighting Faster link highlighting with more types supported Aug 24, 2023
@tim-gromeyer
Copy link
Contributor Author

Works now

@pbek
Copy link
Owner

pbek commented Aug 24, 2023

Works now

Thank you, but currently the closing > are not highlighted.

image

@pbek
Copy link
Owner

pbek commented Aug 24, 2023

LGTM, thank you!

@pbek pbek merged commit 361af8b into pbek:develop Aug 24, 2023
@tim-gromeyer
Copy link
Contributor Author

You are welcome!

@tim-gromeyer tim-gromeyer deleted the more-robust-link-highlighting branch August 24, 2023 13:55
pbek added a commit to pbek/QOwnNotes that referenced this pull request Aug 25, 2023
@pbek
Copy link
Owner

pbek commented Dec 4, 2023

@tim-gromeyer, unfortunately 53c4c598 did break something else too:

    wget http://google.com

http://google.com is now highlighted as link, but it shouldn't.

@pbek
Copy link
Owner

pbek commented Dec 4, 2023

I opened an issue for it #199.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants