mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-21 21:55:09 +00:00
add brackets property of url node
This commit is contained in:
parent
8a7dcab4dd
commit
4c20bcb053
5 changed files with 34 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 詳細
|
||||
- インライン構文。
|
||||
|
||||
|
|
|
@ -362,7 +362,7 @@ hashtagChar
|
|||
url
|
||||
= "<" url:altUrlFormat ">"
|
||||
{
|
||||
return N_URL(url);
|
||||
return N_URL(url, true);
|
||||
}
|
||||
/ url:urlFormat
|
||||
{
|
||||
|
|
|
@ -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 ? '?' : '';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue