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 ### inline media
=> video.mp4 video => video.mp4 video with title prop
=> image.jpg image => image.jpg image with title prop
=> audio.mp3 audio => audio.mp3 audio with title prop
=> video-no-title.mp4 => video-with-no-title.mp4
=> image-no-title.mp4 => image-with-no-title.jpg
=> audio-no-title.mp4 => audio-with-no-title.mp3

View file

@ -3,7 +3,7 @@ import map from "map-stream";
import escape from "escape-html"; import escape from "escape-html";
import * as CSS from "./css.js"; 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) => export const tokenize = (gemtext) =>
JSON.parse(JSON.stringify(gemtext.split("\n").map((line) => GMI_REGEX.exec(line).groups))); 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> </pre>
<p></p> <p></p>
<h3 style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">inline media</h3> <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=\\"video.mp4\\" style=\\"display:block;\\">video with title prop</a>
<a href=\\"image.jpg\\" style=\\"display:block;\\">image</a> <a href=\\"image.jpg\\" style=\\"display:block;\\">image with title prop</a>
<a href=\\"audio.mp3\\" style=\\"display:block;\\">audio</a> <a href=\\"audio.mp3\\" style=\\"display:block;\\">audio with title prop</a>
<p style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">=&gt; video-no-title.mp4 </p> <a href=\\"video-with-no-title.mp4\\" style=\\"display:block;\\">video-with-no-title.mp4</a>
<p style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">=&gt; image-no-title.mp4 </p> <a href=\\"image-with-no-title.jpg\\" style=\\"display:block;\\">image-with-no-title.jpg</a>
<p style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">=&gt; audio-no-title.mp4 </p>" <a href=\\"audio-with-no-title.mp3\\" style=\\"display:block;\\">audio-with-no-title.mp3</a>"
`); `);
expect(toHTML(gemtext, { body: true, css: "none" })).toMatchInlineSnapshot(` expect(toHTML(gemtext, { body: true, css: "none" })).toMatchInlineSnapshot(`
"<h1>gmi-web</h1> "<h1>gmi-web</h1>
@ -66,12 +66,12 @@ test("--body", () => {
</pre> </pre>
<p></p> <p></p>
<h3>inline media</h3> <h3>inline media</h3>
<a href=\\"video.mp4\\">video</a> <a href=\\"video.mp4\\">video with title prop</a>
<a href=\\"image.jpg\\">image</a> <a href=\\"image.jpg\\">image with title prop</a>
<a href=\\"audio.mp3\\">audio</a> <a href=\\"audio.mp3\\">audio with title prop</a>
<p>=&gt; video-no-title.mp4 </p> <a href=\\"video-with-no-title.mp4\\">video-with-no-title.mp4</a>
<p>=&gt; image-no-title.mp4 </p> <a href=\\"image-with-no-title.jpg\\">image-with-no-title.jpg</a>
<p>=&gt; audio-no-title.mp4 </p>" <a href=\\"audio-with-no-title.mp3\\">audio-with-no-title.mp3</a>"
`); `);
}); });
@ -121,12 +121,12 @@ test("--html en", () => {
</pre> </pre>
<p></p> <p></p>
<h3>inline media</h3> <h3>inline media</h3>
<a href=\\"video.mp4\\">video</a> <a href=\\"video.mp4\\">video with title prop</a>
<a href=\\"image.jpg\\">image</a> <a href=\\"image.jpg\\">image with title prop</a>
<a href=\\"audio.mp3\\">audio</a> <a href=\\"audio.mp3\\">audio with title prop</a>
<p>=&gt; video-no-title.mp4 </p> <a href=\\"video-with-no-title.mp4\\">video-with-no-title.mp4</a>
<p>=&gt; image-no-title.mp4 </p> <a href=\\"image-with-no-title.jpg\\">image-with-no-title.jpg</a>
<p>=&gt; audio-no-title.mp4 </p> <a href=\\"audio-with-no-title.mp3\\">audio-with-no-title.mp3</a>
</body> </body>
</html> </html>
" "
@ -168,12 +168,12 @@ test("--image, --audio, --video", () => {
</pre> </pre>
<p></p> <p></p>
<h3 style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">inline media</h3> <h3 style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">inline media</h3>
<video controls src=\\"video.mp4\\" title=\\"video\\"></video> <video controls src=\\"video.mp4\\" title=\\"video with title prop\\"></video>
<img src=\\"image.jpg\\" title=\\"image\\"></img> <img src=\\"image.jpg\\" title=\\"image with title prop\\"></img>
<audio controls src=\\"audio.mp3\\" title=\\"audio\\"></audio> <audio controls src=\\"audio.mp3\\" title=\\"audio with title prop\\"></audio>
<p style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">=&gt; video-no-title.mp4 </p> <video controls src=\\"video-with-no-title.mp4\\"></video>
<p style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">=&gt; image-no-title.mp4 </p> <img src=\\"image-with-no-title.jpg\\"></img>
<p style=\\"margin-top:0;margin-bottom:0;overflow-wrap:break-word;\\">=&gt; audio-no-title.mp4 </p>" <audio controls src=\\"audio-with-no-title.mp3\\"></audio>"
`); `);
}); });
@ -256,24 +256,24 @@ test("tokenize", () => {
}, },
Object { Object {
"href": "video.mp4", "href": "video.mp4",
"title": "video", "title": "video with title prop",
}, },
Object { Object {
"href": "image.jpg", "href": "image.jpg",
"title": "image", "title": "image with title prop",
}, },
Object { Object {
"href": "audio.mp3", "href": "audio.mp3",
"title": "audio", "title": "audio with title prop",
}, },
Object { Object {
"text": "=> video-no-title.mp4 ", "href": "video-with-no-title.mp4",
}, },
Object { Object {
"text": "=> image-no-title.mp4 ", "href": "image-with-no-title.jpg",
}, },
Object { Object {
"text": "=> audio-no-title.mp4 ", "href": "audio-with-no-title.mp3",
}, },
Object { Object {
"text": "", "text": "",