-
-
Notifications
You must be signed in to change notification settings - Fork 245
Markdown improvements regarding tables, nested statements and special character support in links #1647
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
base: main
Are you sure you want to change the base?
Markdown improvements regarding tables, nested statements and special character support in links #1647
Changes from all commits
3c7261c
255f0a9
1008102
ead7613
f9c8e1e
8783b6a
537dbaa
3bc7500
1294cbd
9897900
6d397b7
cec2c11
b2e7988
676a5ab
99e564b
b5c40f8
55e5afe
6eb7f8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ namespace River.OneMoreAddIn.Commands | |
using River.OneMoreAddIn.Models; | ||
using River.OneMoreAddIn.Styles; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using System.Xml.Linq; | ||
|
@@ -51,6 +52,28 @@ public void RewriteHeadings() | |
{ | ||
RewriteHeadings(outline.Descendants(ns + "OE")); | ||
} | ||
|
||
// added header spacing specific to markdown | ||
var quickstyles = page.Root.Elements(ns + "QuickStyleDef"); | ||
foreach (var quickstyle in quickstyles) | ||
{ | ||
var name = quickstyle.Attribute("name").Value; | ||
if (name.Equals("h1") || name.Equals("h2")) | ||
{ | ||
replaceAtributes(quickstyle, spaceBefore: 0.8, spaceAfter: 0.5); | ||
} | ||
else | ||
if (name.Equals("h3") || name.Equals("h4")) | ||
{ | ||
replaceAtributes(quickstyle, spaceBefore: 0.3, spaceAfter: 0.3); | ||
} | ||
} | ||
void replaceAtributes(XElement quickstyle, double spaceBefore, double spaceAfter) | ||
{ | ||
quickstyle.SetAttributeValue("spaceBefore", spaceBefore.ToString("####0.00", CultureInfo.InvariantCulture)); | ||
quickstyle.SetAttributeValue("spaceAfter", spaceAfter.ToString("####0.00", CultureInfo.InvariantCulture)); | ||
} | ||
|
||
} | ||
|
||
|
||
|
@@ -141,8 +164,22 @@ public MarkdownConverter RewriteHeadings(IEnumerable<XElement> paragraphs) | |
} | ||
|
||
|
||
/// <summary> | ||
/// Applies standard OneNote styling to all recognizable headings in all Outlines | ||
/// on the page | ||
/// </summary> | ||
public void RewriteTodo() | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here also, should only affect Outlines that were affected, not all Outlines on page. User can apply custom style after if they want, otherwise abide by existing styles on page. |
||
foreach (var outline in page.BodyOutlines) | ||
{ | ||
RewriteTodo(outline.Descendants(ns + "OE")); | ||
} | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Tag current line with To Do tag if beginning with [ ] or [x] | ||
/// Also :TAGS: will be handled here | ||
/// All other :emojis: should be translated inline by Markdig | ||
/// </summary> | ||
/// <param name="paragraphs"></param> | ||
|
@@ -158,21 +195,46 @@ public MarkdownConverter RewriteTodo(IEnumerable<XElement> paragraphs) | |
{ | ||
var cdata = run.GetCData(); | ||
var wrapper = cdata.GetWrapper(); | ||
if (wrapper.FirstNode is XText) | ||
{ | ||
cdata.Value = wrapper.GetInnerXml(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does absolutely nothing? Convert cdata to wrapper and then set cdata to wrapper XML? That's the same thing. |
||
} | ||
while (wrapper.FirstNode is not XText && wrapper.FirstNode is not null) | ||
{ | ||
wrapper = (XElement)wrapper.FirstNode; | ||
} | ||
if (wrapper.FirstNode is XText text) | ||
{ | ||
var match = boxpattern.Match(text.Value); | ||
// special treatment of todo tag | ||
if (match.Success) | ||
{ | ||
text.Value = text.Value.Substring(match.Length); | ||
|
||
var org = text.Value; | ||
var completed = match.Groups["x"].Value == "x"; | ||
text.Value = text.Value.Replace((completed ? "[x]" : "[ ]"), ""); | ||
cdata.Value = cdata.Value.Replace(org, text.Value); | ||
// ensure TagDef exists | ||
var index = page.AddTagDef("3", "To Do", 4); | ||
|
||
// inject tag prior to run | ||
run.AddBeforeSelf(new Tag(index, match.Groups["x"].Value == "x")); | ||
page.SetTag(paragraph, tagSymbol: "3", tagStatus:completed,tagName:"todo"); | ||
} | ||
else | ||
{ | ||
// look for all other tags | ||
foreach (var t in MarkdownEmojis.taglist) | ||
{ | ||
// check for other tags | ||
if (text.Value.Contains(t.name)) | ||
{ | ||
var org = text.Value; | ||
text.Value = text.Value.Replace(t.name, ""); | ||
cdata.Value = cdata.Value.Replace(org, text.Value); | ||
// ensure TagDef exists | ||
page.SetTag(paragraph, tagSymbol: t.id, tagStatus: false, tagName: t.topic, tagType: t.type); | ||
break; | ||
} | ||
} | ||
|
||
// update run text | ||
cdata.Value = wrapper.GetInnerXml(); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace River.OneMoreAddIn.Commands | ||
{ | ||
public static class MarkdownEmojis | ||
{ | ||
public static List<(string name, string id, string topic, int type)> taglist = new List<(string name, string id, string topic, int type)> | ||
{ | ||
// (":todo:", "3", "todo" , 0), | ||
(":question:", "6", "question" , 0), | ||
(":star:", "13", "important", 0 ), | ||
(":exclamation:", "17", "critical", 0), | ||
(":phone:", "18", "phone", 0), | ||
(":bulb:", "21", "idea", 0), | ||
(":house:", "23", "address", 0), | ||
(":three:", "33", "three", 0), | ||
(":zero:", "39", "zero", 0), | ||
(":two:", "51", "two", 0), | ||
(":arrow_right:", "59", "main agenda item", 0), | ||
(":one:", "70", "one", 0), | ||
(":information_desk_person:","94", "discuss person a/b", 21), | ||
(":bellsymbol:", "97", "bellsymbol", 0), | ||
(":busts_in_silhouette:", "116", "busts_in_silhouette", 0), | ||
(":bell:", "117", "bell", 0), | ||
(":letter:", "118", "letter", 0), | ||
(":musical_note:", "121", "musical_note", 0), | ||
(":secret:", "131", "idea", 0), | ||
(":book:", "132", "book", 0), | ||
(":movie_camera:", "133", "movie_camera", 0), | ||
(":zap:", "140", "lightning_bolt", 0), | ||
(":o:", "1", "default", 0) | ||
}; | ||
|
||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bad assumption. Should only affect Outline where we are converting markdown. Should abide by existing quick style definitions for page. If user wants spacing, they can create their own custom OneMore Style set and apply that after the conversion.