Skip to content

Commit

Permalink
fix(subwaytext): slashlink starts with valid char
Browse files Browse the repository at this point in the history
  • Loading branch information
polyrainbow committed Sep 28, 2024
1 parent fbffd08 commit 9f9c761
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/lib/subwaytext/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,4 +800,24 @@ code inside code

expect(subwaytext(input)).toStrictEqual(expectedResult);
});

it("should not accept two slashes as slashlink", () => {
const input = "//";

const expectedResult = [
{
type: BlockType.PARAGRAPH,
data: {
text: [
{
type: SpanType.NORMAL_TEXT,
text: "//",
},
],
},
},
];

expect(subwaytext(input)).toStrictEqual(expectedResult);
});
});
3 changes: 1 addition & 2 deletions src/lib/subwaytext/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const parseText = (text: string): InlineText => {
let currentSpanType: SpanType | null = null;
let currentSpanText = "";


while (true) {
const step = iterator.next();
if (step.done) {
Expand Down Expand Up @@ -55,7 +54,7 @@ export const parseText = (text: string): InlineText => {
)
&& char === "/"
&& currentSpanType !== SpanType.WIKILINK
&& !isWhiteSpace(iterator.peek(1).join(""))
&& /^[\p{L}\d_]$/u.test(iterator.peek(1).join(""))
) {
if (currentSpanType) {
spans.push({
Expand Down

0 comments on commit 9f9c761

Please sign in to comment.