fix bug with spaces at the end of links

This commit is contained in:
Talon Poole 2021-02-24 20:13:41 +00:00
parent 427bcecefd
commit ae1ae05246
3 changed files with 37 additions and 37 deletions

View file

@ -22,9 +22,9 @@ but even simpler
```
### inline media
=> video.mp4 video
=> image.jpg image
=> audio.mp3 audio
=> video-no-title.mp4
=> image-no-title.mp4
=> audio-no-title.mp4
=> video.mp4 video with title prop
=> image.jpg image with title prop
=> audio.mp3 audio with title prop
=> video-with-no-title.mp4
=> image-with-no-title.jpg
=> audio-with-no-title.mp3

View file

@ -3,7 +3,7 @@ import map from "map-stream";
import escape from "escape-html";
import * as CSS from "./css.js";
export const GMI_REGEX = /^((=>\s?(?<href>[^\s]+)(\s(?<title>.+))?)|(?<pre>```\s?(?<alt>.+)?)|(###\s?(?<h3>.+))|(##\s?(?<h2>.+))|(#\s?(?<h1>.+))|(\*\s?(?<li>.+))|(>\s?(?<quote>.+))|(?<text>(.+)?))$/;
export const GMI_REGEX = /^((=>\s?(?<href>[^\s]+)\s?(?<title>.+)?)|(?<pre>```\s?(?<alt>.+)?)|(###\s?(?<h3>.+))|(##\s?(?<h2>.+))|(#\s?(?<h1>.+))|(\*\s?(?<li>.+))|(>\s?(?<quote>.+))|(?<text>(.+)?))$/;
export const tokenize = (gemtext) =>
JSON.parse(JSON.stringify(gemtext.split("\n").map((line) => GMI_REGEX.exec(line).groups)));

60
spec.js
View file

@ -32,12 +32,12 @@ test("--body", () => {
</pre>
<p></p>
<h3 style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">inline media</h3>
<a href=\\"video.mp4\\" style=\\"display:block;\\">video</a>
<a href=\\"image.jpg\\" style=\\"display:block;\\">image</a>
<a href=\\"audio.mp3\\" style=\\"display:block;\\">audio</a>
<p style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">=&gt; video-no-title.mp4 </p>
<p style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">=&gt; image-no-title.mp4 </p>
<p style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">=&gt; audio-no-title.mp4 </p>"
<a href=\\"video.mp4\\" style=\\"display:block;\\">video with title prop</a>
<a href=\\"image.jpg\\" style=\\"display:block;\\">image with title prop</a>
<a href=\\"audio.mp3\\" style=\\"display:block;\\">audio with title prop</a>
<a href=\\"video-with-no-title.mp4\\" style=\\"display:block;\\">video-with-no-title.mp4</a>
<a href=\\"image-with-no-title.jpg\\" style=\\"display:block;\\">image-with-no-title.jpg</a>
<a href=\\"audio-with-no-title.mp3\\" style=\\"display:block;\\">audio-with-no-title.mp3</a>"
`);
expect(toHTML(gemtext, { body: true, css: "none" })).toMatchInlineSnapshot(`
"<h1>gmi-web</h1>
@ -66,12 +66,12 @@ test("--body", () => {
</pre>
<p></p>
<h3>inline media</h3>
<a href=\\"video.mp4\\">video</a>
<a href=\\"image.jpg\\">image</a>
<a href=\\"audio.mp3\\">audio</a>
<p>=&gt; video-no-title.mp4 </p>
<p>=&gt; image-no-title.mp4 </p>
<p>=&gt; audio-no-title.mp4 </p>"
<a href=\\"video.mp4\\">video with title prop</a>
<a href=\\"image.jpg\\">image with title prop</a>
<a href=\\"audio.mp3\\">audio with title prop</a>
<a href=\\"video-with-no-title.mp4\\">video-with-no-title.mp4</a>
<a href=\\"image-with-no-title.jpg\\">image-with-no-title.jpg</a>
<a href=\\"audio-with-no-title.mp3\\">audio-with-no-title.mp3</a>"
`);
});
@ -121,12 +121,12 @@ test("--html en", () => {
</pre>
<p></p>
<h3>inline media</h3>
<a href=\\"video.mp4\\">video</a>
<a href=\\"image.jpg\\">image</a>
<a href=\\"audio.mp3\\">audio</a>
<p>=&gt; video-no-title.mp4 </p>
<p>=&gt; image-no-title.mp4 </p>
<p>=&gt; audio-no-title.mp4 </p>
<a href=\\"video.mp4\\">video with title prop</a>
<a href=\\"image.jpg\\">image with title prop</a>
<a href=\\"audio.mp3\\">audio with title prop</a>
<a href=\\"video-with-no-title.mp4\\">video-with-no-title.mp4</a>
<a href=\\"image-with-no-title.jpg\\">image-with-no-title.jpg</a>
<a href=\\"audio-with-no-title.mp3\\">audio-with-no-title.mp3</a>
</body>
</html>
"
@ -168,12 +168,12 @@ test("--image, --audio, --video", () => {
</pre>
<p></p>
<h3 style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">inline media</h3>
<video controls src=\\"video.mp4\\" title=\\"video\\"></video>
<img src=\\"image.jpg\\" title=\\"image\\"></img>
<audio controls src=\\"audio.mp3\\" title=\\"audio\\"></audio>
<p style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">=&gt; video-no-title.mp4 </p>
<p style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">=&gt; image-no-title.mp4 </p>
<p style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">=&gt; audio-no-title.mp4 </p>"
<video controls src=\\"video.mp4\\" title=\\"video with title prop\\"></video>
<img src=\\"image.jpg\\" title=\\"image with title prop\\"></img>
<audio controls src=\\"audio.mp3\\" title=\\"audio with title prop\\"></audio>
<video controls src=\\"video-with-no-title.mp4\\"></video>
<img src=\\"image-with-no-title.jpg\\"></img>
<audio controls src=\\"audio-with-no-title.mp3\\"></audio>"
`);
});
@ -256,24 +256,24 @@ test("tokenize", () => {
},
Object {
"href": "video.mp4",
"title": "video",
"title": "video with title prop",
},
Object {
"href": "image.jpg",
"title": "image",
"title": "image with title prop",
},
Object {
"href": "audio.mp3",
"title": "audio",
"title": "audio with title prop",
},
Object {
"text": "=> video-no-title.mp4 ",
"href": "video-with-no-title.mp4",
},
Object {
"text": "=> image-no-title.mp4 ",
"href": "image-with-no-title.jpg",
},
Object {
"text": "=> audio-no-title.mp4 ",
"href": "audio-with-no-title.mp3",
},
Object {
"text": "",