diff --git a/docs/syntax.md b/docs/syntax.md index 825e65539dc1f8973a16d8703e57c0365da5a919..fe73ead94a19fa1378296e88c7a28945dc5a07a2 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -475,6 +475,7 @@ http://hoge.jp/abc ``` ## ノード +構文1: ```js { type: 'url', @@ -484,6 +485,29 @@ http://hoge.jp/abc } ``` +ã¾ãŸã¯ + +```js +{ + type: 'url', + props: { + url: 'https://misskey.io/@ai', + brackets: false + } +} +``` + +構文2: +```js +{ + type: 'url', + props: { + url: 'https://misskey.io/@ai', + brackets: true + } +} +``` + ## 詳細 - インライン構文。 diff --git a/src/internal/parser.pegjs b/src/internal/parser.pegjs index 630957eb7543de56f5cf4c000df284fe11a8f58a..fda5a19b821d77a7f3060ef6464a593f47f05592 100644 --- a/src/internal/parser.pegjs +++ b/src/internal/parser.pegjs @@ -362,7 +362,7 @@ hashtagChar url = "<" url:altUrlFormat ">" { - return N_URL(url); + return N_URL(url, true); } / url:urlFormat { diff --git a/src/internal/util.ts b/src/internal/util.ts index 9bfec389a33b7bd0659dba75a693eb7b41c67321..39ab5971ca1653facbef78ffead27886d8846e92 100644 --- a/src/internal/util.ts +++ b/src/internal/util.ts @@ -79,7 +79,12 @@ export function stringifyNode(node: MfmNode): string { return `#${ node.props.hashtag }`; } case 'url': { - return node.props.url; + if (node.props.brackets) { + return `<${ node.props.url }>`; + } + else { + return node.props.url; + } } case 'link': { const prefix = node.props.silent ? '?' : ''; diff --git a/src/node.ts b/src/node.ts index ac1e29fa27cbbc86a1878b0bb9744cee91582118..03c84538ab6dd350914d83b79262f4349e652336 100644 --- a/src/node.ts +++ b/src/node.ts @@ -143,10 +143,11 @@ export type MfmUrl = { type: 'url'; props: { url: string; + brackets?: boolean; }; children?: []; }; -export const N_URL = (value: string): NodeType<'url'> => { return { type:'url', props: { url: value } }; }; +export const N_URL = (value: string, brackets?: boolean): NodeType<'url'> => { return { type:'url', props: { url: value, brackets } }; }; export type MfmLink = { type: 'link'; diff --git a/test/parser.ts b/test/parser.ts index eda18da2e6253a6aed97dbab87cd8181657c0f0f..489c821cdef6bb6add198946174e8f3e1b1b9fce 100644 --- a/test/parser.ts +++ b/test/parser.ts @@ -878,7 +878,7 @@ hoge`; it('match non-ascii characters contained url with angle brackets', () => { const input = '<https://大石泉ã™ã.example.com>'; const output = [ - N_URL('https://大石泉ã™ã.example.com'), + N_URL('https://大石泉ã™ã.example.com', true), ]; assert.deepStrictEqual(mfm.parse(input), output); });