Bug 406333 - Markdown addon: support syntax highlighting
Summary: Markdown addon: support syntax highlighting
Status: RESOLVED FIXED
Alias: None
Product: kdepim
Classification: Applications
Component: messagecomposer (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-08 14:42 UTC by avlas
Modified: 2019-04-18 05:53 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 5.12.0


Attachments
Screenshot (117.73 KB, image/png)
2019-04-17 16:01 UTC, Laurent Montel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description avlas 2019-04-08 14:42:19 UTC
An example from https://markdown-here.com :

```javascript
// All the code you will ever need
var hw = "Hello World!"
alert(hw);
```
Comment 1 Laurent Montel 2019-04-08 20:16:04 UTC
Yep indeed but "Discount" lib seems that it doesn't support style :(
Comment 2 avlas 2019-04-08 20:45:14 UTC
Thanks a lot for working on the Markdown plugin. It's very nice and useful!

> Yep indeed but "Discount" lib seems that it doesn't support style :(
(In reply to Laurent Montel from comment #1)

I see. I wonder how difficult would be to build upon markdown-here instead. I guess very difficult...
Comment 3 Laurent Montel 2019-04-09 05:00:54 UTC
When I started to implement this feature, I looked at first markdown-here.
But it was very hard to use js in kmail directly...
Comment 4 avlas 2019-04-09 14:53:49 UTC
(In reply to Laurent Montel from comment #3)
> When I started to implement this feature, I looked at first markdown-here.
> But it was very hard to use js in kmail directly...

I see. Thanks for the info.
Comment 5 avlas 2019-04-09 14:54:04 UTC
I submitted an issue to Discount to see if this could be implemented: https://github.com/Orc/discount/issues/203
Comment 6 avlas 2019-04-09 14:59:26 UTC
Discount dev replied this:

"Discount doesn't know about the structure of codeblocks, so it can't do it natively. I could implement a code block callback so that an external function could apply syntax highlighting, though?" (https://github.com/Orc/discount/issues/203#issuecomment-481283980)

Laurent, could you please give your view on this? Thank you!
Comment 7 avlas 2019-04-10 12:15:22 UTC
Would "a code block callback so that an external function could apply syntax highlighting" be useful for applying highlighting in Kmail via Kpart?
Comment 8 Laurent Montel 2019-04-10 13:35:26 UTC
(In reply to avlas from comment #7)
> Would "a code block callback so that an external function could apply syntax
> highlighting" be useful for applying highlighting in Kmail via Kpart?

It's not necessary to use kpart. We have a lib for my highlighting.
For sure if we have a code block callback I will be able to highlight it.
Comment 9 avlas 2019-04-10 13:37:11 UTC
(In reply to Laurent Montel from comment #8)
> (In reply to avlas from comment #7)
> > Would "a code block callback so that an external function could apply syntax
> > highlighting" be useful for applying highlighting in Kmail via Kpart?
> 
> It's not necessary to use kpart. We have a lib for my highlighting.
> For sure if we have a code block callback I will be able to highlight it.

Awesome!
Comment 10 avlas 2019-04-12 15:46:26 UTC
> It's not necessary to use kpart. We have a lib for my highlighting.
> For sure if we have a code block callback I will be able to highlight it.

Laurent, Discount dev has finished implementing this and asks if you could please test it:

"It Works For Me(tm) -- can the Kmail crew check it out for nontrivial external formatting (I don't do any syntax highlighting in my little test callback, I just wanted to make certain it works)?"
Comment 11 avlas 2019-04-12 15:48:27 UTC
(In reply to avlas from comment #10)
> Laurent, Discount dev has finished implementing this and asks if you could
> please test it:
> 
> "It Works For Me(tm) -- can the Kmail crew check it out for nontrivial
> external formatting (I don't do any syntax highlighting in my little test
> callback, I just wanted to make certain it works)?"

Forgot to say that the code is the master branch: https://github.com/Orc/discount
Comment 12 avlas 2019-04-12 16:33:51 UTC
(In reply to avlas from comment #11)
> (In reply to avlas from comment #10)
> > Laurent, Discount dev has finished implementing this and asks if you could
> > please test it:
> > 
> > "It Works For Me(tm) -- can the Kmail crew check it out for nontrivial
> > external formatting (I don't do any syntax highlighting in my little test
> > callback, I just wanted to make certain it works)?"
> 
> Forgot to say that the code is the master branch:
> https://github.com/Orc/discount

Laurent, it was quite easy to compile discount. If there would be an easy way to check highlighting without compiling kmail (which seems scary!), I'd like to give it a try...
Comment 13 Laurent Montel 2019-04-13 07:52:40 UTC
Yep I will test it for sure :)
But I am not sure to testing it this WE.
But for sure I will do next week :)

Thanks for motivating dev to implement it :)
Comment 14 Laurent Montel 2019-04-16 06:46:30 UTC
Git commit b072aae3cb9e4e562b36ef852c6edbac8b630ba2 by Laurent Montel.
Committed on 16/04/2019 at 06:44.
Pushed by mlaurent into branch 'master'.

Start to implement highlighting

M  +10   -0    kmail/editorconvertertextplugins/markdown/markdownconverter.cpp

https://commits.kde.org/kdepim-addons/b072aae3cb9e4e562b36ef852c6edbac8b630ba2
Comment 15 Laurent Montel 2019-04-17 11:44:37 UTC
Git commit c1620855005155028cb1e88a739abe9adf066353 by Laurent Montel.
Committed on 17/04/2019 at 11:43.
Pushed by mlaurent into branch 'master'.

Fix Bug 406333 - Markdown addon: support syntax highlighting
FIXED-IN: 5.12.0

M  +2    -1    kmail/editorconvertertextplugins/markdown/CMakeLists.txt
M  +5    -5    kmail/editorconvertertextplugins/markdown/autotests/CMakeLists.txt
M  +23   -43   kmail/editorconvertertextplugins/markdown/markdownconverter.cpp
A  +87   -0    kmail/editorconvertertextplugins/markdown/markdownhighlighter.cpp     [License: GPL (v2+)]
A  +42   -0    kmail/editorconvertertextplugins/markdown/markdownhighlighter.h     [License: GPL (v2+)]
M  +2    -2    kmail/editorconvertertextplugins/markdown/tests/CMakeLists.txt

https://commits.kde.org/kdepim-addons/c1620855005155028cb1e88a739abe9adf066353
Comment 16 Laurent Montel 2019-04-17 11:45:10 UTC
Now we can hightlight block.
I need to fix some little bugs but it's good now :)
Comment 17 avlas 2019-04-17 11:50:47 UTC
(In reply to Laurent Montel from comment #16)
> Now we can hightlight block.
> I need to fix some little bugs but it's good now :)

Excellent!

[ If you'd have a chance and it's not too much trouble, please attach a screenshot of an example. I'd love to see it in action :) ]
Comment 18 Laurent Montel 2019-04-17 16:01:01 UTC
Created attachment 119461 [details]
Screenshot
Comment 19 avlas 2019-04-17 16:02:52 UTC
(In reply to Laurent Montel from comment #18)
> Created attachment 119461 [details]
> Screenshot

Neat! (thank you)
Comment 20 avlas 2019-04-18 04:37:04 UTC
(In reply to Laurent Montel from comment #18)
> Created attachment 119461 [details]
> Screenshot

I had some ideas for further enhancement after seeing your screenshot (as well as this one http://25.io/mou/img/1@2x.png):

1) It would be great if Kmail composer would use KSyntaxHighlighting technology as well to ease writing emails in markdown format, so it gets automatically enabled when the markdown button in the composer is activated.

2) It would be so great to have a live preview (as shown in the link above; please note that Kate has already something similar to this) instead of a pop-up window.

3) It would be nice if there could be an option to remember the status of the Markdown button in the composer.

Please let me know if these ideas make sense and if you would like me to open new bug reports for them, especially points 2 and 3 above, which are not about highlighting.

I can easily foresee myself in the near future writing all my emails in markdown format instead of plain text :)
Comment 21 Laurent Montel 2019-04-18 04:53:04 UTC
(In reply to avlas from comment #20)
> (In reply to Laurent Montel from comment #18)
> > Created attachment 119461 [details]
> > Screenshot
> 
> I had some ideas for further enhancement after seeing your screenshot (as
> well as this one http://25.io/mou/img/1@2x.png):
> 
> 1) It would be great if Kmail composer would use KSyntaxHighlighting
> technology as well to ease writing emails in markdown format, so it gets
> automatically enabled when the markdown button in the composer is activated.

KSyntaxHighlighting highlights only text, it can create a html code but not for converting
markdown to html.

> 2) It would be so great to have a live preview (as shown in the link above;
> please note that Kate has already something similar to this) instead of a
> pop-up window.

We can't do it as composer is a "QTextEdit" and we need a html viewer/editor for showing
mardown result. QTextEdit is too limited for html.

> 
> 3) It would be nice if there could be an option to remember the status of
> the Markdown button in the composer.

We can do it. I will look at it.

> 
> Please let me know if these ideas make sense and if you would like me to
> open new bug reports for them, especially points 2 and 3 above, which are
> not about highlighting.
> 
> I can easily foresee myself in the near future writing all my emails in
> markdown format instead of plain text :)
Comment 22 avlas 2019-04-18 05:07:04 UTC
(In reply to Laurent Montel from comment #21)
> (In reply to avlas from comment #20)
> > (In reply to Laurent Montel from comment #18)
> > > Created attachment 119461 [details]
> > > Screenshot
> > 
> > I had some ideas for further enhancement after seeing your screenshot (as
> > well as this one http://25.io/mou/img/1@2x.png):
> > 
> > 1) It would be great if Kmail composer would use KSyntaxHighlighting
> > technology as well to ease writing emails in markdown format, so it gets
> > automatically enabled when the markdown button in the composer is activated.
> 
> KSyntaxHighlighting highlights only text, it can create a html code but not
> for converting
> markdown to html.

Sorry, I think I didn't explain myself well. I was not talking here now about the conversion from markdown to html, but about highlighting the email body in the composer while writing (if/when the markdown button is activated). In that case, it would be great to see how markdown keywords written in plain text get automatically highlighted. This would help writing markdown emails, e.g. to better structure the email or more easily visualize markdown typos.

> > 2) It would be so great to have a live preview (as shown in the link above;
> > please note that Kate has already something similar to this) instead of a
> > pop-up window.
> 
> We can't do it as composer is a "QTextEdit" and we need a html viewer/editor
> for showing
> mardown result. QTextEdit is too limited for html.

I see. That's a pity, such a feature would probably attract users, especially KDE users using markdown-here in other email client applications or in the browser.

I know there is the option but never tried using an external editor for writing emails. I assume this would not be an option for writing emails in markdown either, right? Saying because perhaps one could use Kate for this...

> > 3) It would be nice if there could be an option to remember the status of
> > the Markdown button in the composer.
> 
> We can do it. I will look at it.

Thank you!
Comment 23 Laurent Montel 2019-04-18 05:41:05 UTC
(In reply to avlas from comment #22)
> (In reply to Laurent Montel from comment #21)
> > (In reply to avlas from comment #20)
> > > (In reply to Laurent Montel from comment #18)
> > > > Created attachment 119461 [details]
> > > > Screenshot
> > > 
> > > I had some ideas for further enhancement after seeing your screenshot (as
> > > well as this one http://25.io/mou/img/1@2x.png):
> > > 
> > > 1) It would be great if Kmail composer would use KSyntaxHighlighting
> > > technology as well to ease writing emails in markdown format, so it gets
> > > automatically enabled when the markdown button in the composer is activated.
> > 
> > KSyntaxHighlighting highlights only text, it can create a html code but not
> > for converting
> > markdown to html.
> 
> Sorry, I think I didn't explain myself well. I was not talking here now
> about the conversion from markdown to html, but about highlighting the email
> body in the composer while writing (if/when the markdown button is
> activated). In that case, it would be great to see how markdown keywords
> written in plain text get automatically highlighted. This would help writing
> markdown emails, e.g. to better structure the email or more easily visualize
> markdown typos.

Ah ok. I don't know if it's possible but indeed I can look at it.

> 
> > > 2) It would be so great to have a live preview (as shown in the link above;
> > > please note that Kate has already something similar to this) instead of a
> > > pop-up window.
> > 
> > We can't do it as composer is a "QTextEdit" and we need a html viewer/editor
> > for showing
> > mardown result. QTextEdit is too limited for html.
> 
> I see. That's a pity, such a feature would probably attract users,
> especially KDE users using markdown-here in other email client applications
> or in the browser.

yep but in thunderbird they use a html editor directly...
It's not possible in Qt.

> 
> I know there is the option but never tried using an external editor for
> writing emails. I assume this would not be an option for writing emails in
> markdown either, right? Saying because perhaps one could use Kate for this...
> 
> > > 3) It would be nice if there could be an option to remember the status of
> > > the Markdown button in the composer.
> > 
> > We can do it. I will look at it.
> 
> Thank you!
Comment 24 avlas 2019-04-18 05:53:54 UTC
(In reply to Laurent Montel from comment #23)
> > Sorry, I think I didn't explain myself well. I was not talking here now
> > about the conversion from markdown to html, but about highlighting the email
> > body in the composer while writing (if/when the markdown button is
> > activated). In that case, it would be great to see how markdown keywords
> > written in plain text get automatically highlighted. This would help writing
> > markdown emails, e.g. to better structure the email or more easily visualize
> > markdown typos.
> 
> Ah ok. I don't know if it's possible but indeed I can look at it.

Great, thanks