Jump to content

Talk:VisualEditor/API/Data Model/Surface

Add topic
From mediawiki.org
Latest comment: 6 years ago by Adamw in topic Request for clarification

Request for clarification

[edit]

Beginner feedback: I would love to see a paragraph added, explaining how to get a surfaceModel. Adamw (talk) 11:49, 7 October 2019 (UTC)Reply

I would love to see a paragraph added, explaining all methods of fragments like insertContent etc.

Structures here - is objects or variable in JSON format, that need to insert content in fragment, which is not wrapped in

<nowiki>

tags, allowing you to add content with wiki markup.

Examples of permitted structures

[edit]

Adding redirect to Page

[edit]
var redirectContent = [{
						type: 'mwRedirect',
						attributes: {title: 'Page'}
					  }];
fragment.collapseToStart().insertContent(redirectContent);

Template with values

[edit]
[{
    type: 'mwTransclusionBlock',
    attributes: {
        mw: {
            parts: [
                {
                    template: {
                        target: { href: 'Template:MyTemplate', wt: 'MyTemplate' },
                        params: { 1: { wt: 'my parameter' } }
                    }
                }
            ]
        }
    }
},
{ type: '/mwTransclusionBlock' } /*???*/]
[edit]
[{
    type: 'link',
    attributes: {
        href: 'https://example.com',
        title: 'Пример ссылки'
    },
    content: 'Пример ссылки'
}]

Images

[edit]
[{
    type: 'image',
    attributes: {
        src: 'File:Example.jpg',
        alt: 'Пример изображения'
    }
}]