Skip to content

Commit

Permalink
Adding support for higlighting text in Markdown blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
phase1geo committed Oct 12, 2024
1 parent b09c72e commit db29b6a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 24 deletions.
56 changes: 35 additions & 21 deletions data/syntax/mosaic-markdown.lang
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,29 @@
</metadata>

<styles>
<style id="header" name="Header" map-to="def:heading"/>
<style id="header1" name="Header1" map-to="def:heading"/>
<style id="header2" name="Header2" map-to="def:heading"/>
<style id="header3" name="Header3" map-to="def:heading"/>
<style id="header4" name="Header4" map-to="def:heading"/>
<style id="header5" name="Header5" map-to="def:heading"/>
<style id="header6" name="Header6" map-to="def:heading"/>
<style id="horizontal-rule" name="Horizontal Rule" map-to="def:thematic-break"/>
<style id="list-marker" name="List Marker" map-to="def:list-marker"/>
<style id="code-span" name="Code Span" map-to="def:inline-code"/>
<style id="code-block" name="Code Block" map-to="def:preformatted-section"/>
<style id="header" name="Header" map-to="def:heading"/>
<style id="header1" name="Header1" map-to="def:heading"/>
<style id="header2" name="Header2" map-to="def:heading"/>
<style id="header3" name="Header3" map-to="def:heading"/>
<style id="header4" name="Header4" map-to="def:heading"/>
<style id="header5" name="Header5" map-to="def:heading"/>
<style id="header6" name="Header6" map-to="def:heading"/>
<style id="horizontal-rule" name="Horizontal Rule" map-to="def:thematic-break"/>
<style id="list-marker" name="List Marker" map-to="def:list-marker"/>
<style id="code-span" name="Code Span" map-to="def:inline-code"/>
<style id="code-block" name="Code Block" map-to="def:preformatted-section"/>
<style id="blockquote-marker" name="Blockquote Marker" map-to="def:shebang"/>
<style id="url" name="URL" map-to="def:link-destination"/>
<style id="link-text" name="Link Text" map-to="def:link-text"/>
<style id="label" name="Label" map-to="def:preprocessor"/>
<style id="attribute-value" name="Attribute Value" map-to="def:constant"/>
<style id="image-marker" name="Image Marker" map-to="def:link-symbol"/>
<style id="emphasis" name="Emphasis" map-to="def:emphasis"/>
<style id="strong-emphasis" name="Strong Emphasis" map-to="def:strong-emphasis"/>
<style id="strikethrough" name="Strikethrough" map-to="def:deletion"/>
<style id="backslash-escape" name="Backslash Escape" map-to="def:special-char"/>
<style id="line-break" name="Line Break" map-to="def:note"/>
<style id="url" name="URL" map-to="def:link-destination"/>
<style id="link-text" name="Link Text" map-to="def:link-text"/>
<style id="label" name="Label" map-to="def:preprocessor"/>
<style id="attribute-value" name="Attribute Value" map-to="def:constant"/>
<style id="image-marker" name="Image Marker" map-to="def:link-symbol"/>
<style id="emphasis" name="Emphasis" map-to="def:emphasis"/>
<style id="strong-emphasis" name="Strong Emphasis" map-to="def:strong-emphasis"/>
<style id="strikethrough" name="Strikethrough" map-to="def:deletion"/>
<style id="highlight" name="Highlight" map-to="def:note"/>
<style id="backslash-escape" name="Backslash Escape" map-to="def:special-char"/>
<style id="line-break" name="Line Break" map-to="def:note"/>
</styles>

<definitions>
Expand Down Expand Up @@ -214,6 +215,7 @@
<context ref="underscores-strong-emphasis"/>
<context ref="asterisks-strong-emphasis"/>
<context ref="strikethrough"/>
<context ref="highlight"/>
<context ref="backslash-escape"/>
<context ref="line-break"/>
</include>
Expand Down Expand Up @@ -398,6 +400,17 @@
</include>
</context>

<!-- Examples:
Lorem ==highlight== sit amet.
-->
<context id="highlight">
<match>==([^= \t].*?(?&lt;!\\|\=| |\t))==</match>

<include>
<context sub-pattern="1" style-ref="highlight"/>
</include>
</context>

<context id="backslash-escape" style-ref="backslash-escape">
<match>\\[\\`*_{}\[\]()#+-.!]</match>
</context>
Expand Down Expand Up @@ -441,6 +454,7 @@
<context ref="underscores-strong-emphasis"/>
<context ref="asterisks-strong-emphasis"/>
<context ref="strikethrough"/>
<context ref="highlight"/>
<context ref="backslash-escape"/>
<context ref="line-break"/>
</include>
Expand Down
4 changes: 2 additions & 2 deletions src/Export.vala
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public class Export {
}

command += "-f";
command += "commonmark";
command += "markdown+mark";
command += "--embed-resources";
command += "--standalone";
command += "-o";
Expand All @@ -262,4 +262,4 @@ public class Export {

}

}
}
12 changes: 11 additions & 1 deletion src/MarkdownFuncs.vala
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class MarkdownFuncs {
<snippet _name="md-strike" _description="Insert strikethrough text" trigger="%md-strike%">
<text languages="markdown"><![CDATA[~~${1}~~$0]]></text>
</snippet>
<snippet _name="md-hilite" _description="Insert highlighted text" trigger="%md-hilite%">
<text languages="markdown"><![CDATA[==${1}==$0]]></text>
</snippet>
<snippet _name="md-monospace" _description="Insert monospaced text" trigger="%md-mono%">
<text languages="markdown"><![CDATA[`${1}`$0]]></text>
</snippet>
Expand Down Expand Up @@ -343,11 +346,18 @@ public class MarkdownFuncs {
add_text_markup( view, buffer, "_", "_", "%md-italic%" );
}

/* Adds Markdown strikethrough syntax around selected text */
//-------------------------------------------------------------
// Adds Markdown strikethrough syntax around selected text
public static void insert_strikethrough_text( GtkSource.View view, TextBuffer buffer ) {
add_text_markup( view, buffer, "~~", "~~", "%md-strike%" );
}

//-------------------------------------------------------------
// Adds Markdown highlight syntax around selected text
public static void insert_highlight_text( GtkSource.View view, TextBuffer buffer ) {
add_text_markup( view, buffer, "==", "==", "%md-hilite%" );
}

/* Adds Markdown code syntax around selected text */
public static void insert_code_text( GtkSource.View view, TextBuffer buffer ) {

Expand Down

0 comments on commit db29b6a

Please sign in to comment.