MCPcopy
hub / github.com/tinymce/tinymce / updateHtml

Function updateHtml

modules/tinymce/src/plugins/media/main/ts/core/UpdateHtml.ts:33–122  ·  view source on GitHub ↗
(html: string, data: Partial<MediaData>, updateAll?: boolean, schema?: Schema)

Source from the content-addressed store, hash-verified

31type SourceMime = `${Source}mime`;
32
33const updateHtml = (html: string, data: Partial<MediaData>, updateAll?: boolean, schema?: Schema): string => {
34 let numSources = 0;
35 let sourceCount = 0;
36
37 const parser = Parser(schema);
38 parser.addNodeFilter('source', (nodes) => numSources = nodes.length);
39 const rootNode = parser.parse(html);
40
41 for (let node: AstNode | null | undefined = rootNode; node; node = node.walk()) {
42 if (node.type === 1) {
43 const name = node.name;
44
45 if (node.attr('data-ephox-embed-iri')) {
46 updateEphoxEmbed(data, node);
47 // Don't continue to update if we find an EME embed
48 break;
49 } else {
50 switch (name) {
51 case 'video':
52 case 'object':
53 case 'embed':
54 case 'img':
55 case 'iframe':
56 if (data.height !== undefined && data.width !== undefined) {
57 node.attr('width', data.width);
58 node.attr('height', data.height);
59 }
60 break;
61 }
62
63 if (updateAll) {
64 switch (name) {
65 case 'video':
66 node.attr('poster', data.poster);
67 node.attr('src', null);
68
69 // Add <source> child elements
70 for (let index = numSources; index < 2; index++) {
71 if (data[sources[index]]) {
72 const source = new AstNode('source', 1);
73 source.attr('src', data[sources[index]]);
74 source.attr('type', data[sources[index] + 'mime' as SourceMime] || null);
75 node.append(source);
76 }
77 }
78 break;
79
80 case 'iframe':
81 node.attr('src', data.source);
82 break;
83
84 case 'object':
85 const hasImage = node.getAll('img').length > 0;
86 if (data.poster && !hasImage) {
87 node.attr('src', data.poster);
88
89 const img = new AstNode('img', 1);
90 img.attr('src', data.poster);

Callers

nothing calls this directly

Calls 8

attrMethod · 0.95
ParserFunction · 0.90
updateEphoxEmbedFunction · 0.85
walkMethod · 0.80
appendMethod · 0.80
getAllMethod · 0.80
removeMethod · 0.65
HtmlSerializerFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…