pbek/qmarkdowntextedit

Option to disable sub headers by dashes/equal-signs?

nuttyartist opened this issue · 7 comments

Hi, @pbek!

Is there an option to disable the behaviour of --- or === creating sub headlines?
Or at least/also an option just to disable the background highlighting of these?

Thanks!

pbek commented

Is there an option to disable the behaviour of --- or === creating sub headlines?

Which behaviour are we takling about? 😅

Or at least/also an option just to disable the background highlighting of these?

You could customize the styling completely like QOwnNotes does.

Which behaviour are we takling about? 😅

Screen Shot 2023-07-04 at 8 29 21 AM

Is there an option to disable the creation of headers by dashes/equals below text, and to remove the background color on dashes in the second example?

pbek commented

Is there an option to disable the creation of headers by dashes/equals below text

No, not really, that's just Markdown. Why would you want to disable that specific syntax of Markdown?
You could always just override the one method that applies that highlighting.

and to remove the background color on dashes in the second example?

You can just override the style, like in:

https://github.com/pbek/QOwnNotes/blob/22f7016849cce3d2f01a35c1eb62f9869029a26e/src/widgets/qownnotesmarkdowntextedit.cpp#L184

https://github.com/pbek/QOwnNotes/blob/22f7016849cce3d2f01a35c1eb62f9869029a26e/src/widgets/qownnotesmarkdowntextedit.cpp#L124

No, not really, that's just Markdown. Why would you want to disable that specific syntax of Markdown?

Sometimes I (and I believe many others, especially non Markdown users) just want to create a line seperator below some text without formatting the text above it as a header. But I think I'll keep the current behavior, it's just good to know I can ovveride it.

You can just override the style, like in:

Awesome, thanks!

Two more questions:

  1. I want to set the font size for code blocks, so they're smaller than the regular text. So I did something like that:
qreal codeBlockFontSize = fontSize - 2;
    _formats[static_cast<HighlighterState>(HighlighterState::InlineCodeBlock)].setFontPointSize(codeBlockFontSize);
    _formats[static_cast<HighlighterState>(HighlighterState::CodeBlock)].setFontPointSize(codeBlockFontSize);
    _formats[static_cast<HighlighterState>(HighlighterState::CodeBlockComment)].setFontPointSize(codeBlockFontSize);

But the size of some syntex of cpp stays the same while the rest does gets smaller (I set a very small number below just to show the difference):

Screen Shot 2023-07-09 at 10 43 58 AM

  1. Do you think you can add marking/highlighting a piece of text syntax like Bear is doing here with two colons around a piece of text to highlight it?

Screen Shot 2023-07-09 at 10 48 05 AM

pbek commented
  1. hard to tell without actually playing around with the code
  2. since that's no Markdown syntax, it's best to implement that somewhere else. QOwnNotes for example has a script function to do that

That's our customMarkdownHighlighter.cpp. Did I miss any HighlighterState in my code above?

pbek commented

Well, there are lots of code-states:

enum HighlighterState {
NoState = -1,
Link = 0,
Image = 3,
CodeBlock,
CodeBlockComment,
Italic = 7,
Bold,
List,
Comment = 11,
H1,
H2,
H3,
H4,
H5,
H6,
BlockQuote,
HorizontalRuler = 21,
Table,
InlineCodeBlock,
MaskedSyntax,
CurrentLineBackgroundColor,
BrokenLink,
FrontmatterBlock,
TrailingSpace,
CheckBoxUnChecked,
CheckBoxChecked,
StUnderline,
// code highlighting
CodeKeyWord = 1000,
CodeString = 1001,
CodeComment = 1002,
CodeType = 1003,
CodeOther = 1004,
CodeNumLiteral = 1005,
CodeBuiltIn = 1006,
// internal
CodeBlockIndented = 96,
CodeBlockTildeEnd = 97,
CodeBlockTilde = 98,
CodeBlockTildeComment,
CodeBlockEnd = 100,
HeadlineEnd,
FrontmatterBlockEnd,
// languages
/*********
* When adding a language make sure that its value is a multiple of 2
* This is because we use the next number as comment for that language
* In case the language doesn't support multiline comments in the
* traditional C++ sense, leave the next value empty. Otherwise mark the
* next value as comment for that language. e.g CodeCpp = 200
* CodeCppComment = 201
*/
CodeCpp = 200,
CodeCppComment = 201,
CodeJs = 202,
CodeJsComment = 203,
CodeC = 204,
CodeCComment = 205,
CodeBash = 206,
CodePHP = 208,
CodePHPComment = 209,
CodeQML = 210,
CodeQMLComment = 211,
CodePython = 212,
CodeRust = 214,
CodeRustComment = 215,
CodeJava = 216,
CodeJavaComment = 217,
CodeCSharp = 218,
CodeCSharpComment = 219,
CodeGo = 220,
CodeGoComment = 221,
CodeV = 222,
CodeVComment = 223,
CodeSQL = 224,
CodeJSON = 226,
CodeXML = 228,
CodeCSS = 230,
CodeCSSComment = 231,
CodeTypeScript = 232,
CodeTypeScriptComment = 233,
CodeYAML = 234,
CodeINI = 236,
CodeTaggerScript = 238,
CodeVex = 240,
CodeVexComment = 241,
CodeCMake = 242,
CodeMake = 244,
CodeNix = 246,
CodeForth = 248,
CodeForthComment = 249
};