// The HTML a repository's markdown is allowed to keep. // // A README writes tags of its own for what markdown has no syntax for: a row // of screenshots, a centred banner, a collapsed section. That text belongs to // whoever wrote the repository, so none of it may reach the page as markup of // its own choosing. // // This module reads the tags and writes them again. A tag in the result // carries a name from the list below, attributes from the list below, and // values this file escaped. Every other tag is dropped, and for a few of them // the text between the tags is dropped as well. Rewriting is what makes the // result small enough to read: a mistake in the reader can lose a tag, but it // cannot invent one. /** Tags a document may open, each with the attributes it may carry. */ const TAGS = { a: ['href'], abbr: [], b: [], big: [], blockquote: [], br: [], caption: [], center: [], cite: [], code: [], col: ['span', 'width'], colgroup: ['span'], dd: [], del: [], details: ['open'], dfn: [], div: [], dl: [], dt: [], em: [], figcaption: [], figure: [], h1: [], h2: [], h3: [], h4: [], h5: [], h6: [], hr: [], i: [], img: ['src', 'alt', 'width', 'height'], ins: [], kbd: [], li: [], mark: [], ol: ['start', 'type'], p: [], picture: [], pre: [], q: [], s: [], samp: [], small: [], span: [], strike: [], strong: [], sub: [], summary: [], sup: [], table: [], tbody: [], td: ['colspan', 'rowspan', 'valign'], tfoot: [], th: ['colspan', 'rowspan', 'valign'], thead: [], time: [], tr: [], tt: [], u: [], ul: [], var: [], wbr: [], }; /** Attributes any tag on the list may carry. */ const GLOBAL = ['align', 'title']; /** Tags that take no closing tag. */ const VOID = new Set(['br', 'col', 'hr', 'img', 'wbr']); /** Attributes whose presence is the whole value. */ const BOOLEAN = new Set(['open']); /** * Tags whose text is dropped along with the tag. A `