Skip to content

Commit 4160ee8

Browse files
notes@schorschii: Add basic markdown support (#1761)
* Closes #1681
1 parent a151a65 commit 4160ee8

2 files changed

Lines changed: 71 additions & 5 deletions

File tree

notes@schorschii/README.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
1-
# Note Desklet
2-
3-
## Contributions
4-
- code and first themes by _schorschii_
5-
- many new note themes and logo by _Niki_
1+
# Note Desklet
2+
3+
## Basic markdown support
4+
5+
1. Headlines
6+
7+
Write headlines like this:
8+
```
9+
# Headline 1
10+
## Headline 2
11+
### Headline 3
12+
#### Headline 4
13+
##### Headline 5
14+
###### Headline 6
15+
```
16+
2. Bold text
17+
18+
Write **bold text** like this:
19+
```
20+
**text**
21+
```
22+
23+
3. Italic text
24+
25+
Write *italic text* like this:
26+
```
27+
*text*
28+
```
29+
4. Strikethrough text
30+
31+
Write ~~strikethrough~~ text like this:
32+
```
33+
~~text~~
34+
```
35+
5. Monospace text
36+
37+
Write `monospace` text like this:
38+
```
39+
`text`
40+
```
41+
42+
## Contributions
43+
- code and first themes by _schorschii_
44+
- many new note themes and logo by _Niki_

notes@schorschii/files/notes@schorschii/desklet.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,15 @@ MyDesklet.prototype = {
290290
//Main.notifyError("Complete Refresh Done", " "); // debug
291291
}
292292

293+
// parse markdown
294+
this.notecontent = this.parseMarkdown(this.notecontent);
295+
293296
// set the raw text
294297
this.notetext.set_text(this.notecontent);
295298

299+
// enable markup to support markdown
300+
this.notetext.clutter_text.set_use_markup(true);
301+
296302
// grab the Clutter.Text layout
297303
let ct = this.notetext.get_clutter_text();
298304

@@ -307,6 +313,27 @@ MyDesklet.prototype = {
307313
//Main.notifyError("Text Refresh Done", " "); // debug
308314
},
309315

316+
parseMarkdown: function(text) {
317+
// bold by **text**
318+
text = text.replace(/\*\*(.*?)\*\*/g, '<b>$1</b>');
319+
// italic by *text*
320+
text = text.replace(/\*(.*?)\*/g, '<i>$1</i>');
321+
// strikethrough by ~~text~~
322+
text = text.replace(/~~(.*?)~~/g, '<s>$1</s>');
323+
// monospace by `text`
324+
text = text.replace(/`(.*?)`/g, '<tt>$1</tt>');
325+
326+
// headlines
327+
text = text.replace(/^# (.*)$/gm, '<span size="150%"><b>$1</b></span>');
328+
text = text.replace(/^## (.*)$/gm, '<span size="130%"><b>$1</b></span>');
329+
text = text.replace(/^### (.*)$/gm, '<span size="110%"><b>$1</b></span>');
330+
text = text.replace(/^#### (.*)$/gm, '<span size="90%"><b>$1</b></span>');
331+
text = text.replace(/^##### (.*)$/gm, '<span size="70%"><b>$1</b></span>');
332+
text = text.replace(/^###### (.*)$/gm, '<span size="50%"><b>$1</b></span>');
333+
334+
return text;
335+
},
336+
310337
refreshDecoration: function() {
311338
// desklet label (header)
312339
if(this.useCustomLabel == true)

0 commit comments

Comments
 (0)