'use strict'; /* global $:off */ /** * @external CommentItem */ var utils = require( './utils.js' ); /** * Add an attribute to a list item to remove pre-whitespace in Parsoid * * @param {HTMLElement} listItem List item element */ function whitespaceParsoidHack( listItem ) { // HACK: Setting data-parsoid removes the whitespace after the list item, // which makes nested lists work. // This is undocumented behaviour and probably very fragile. listItem.setAttribute( 'data-parsoid', '{}' ); } /** * Remove extra linebreaks from a wikitext string * * @param {string} wikitext Wikitext * @return {string} */ function sanitizeWikitextLinebreaks( wikitext ) { return utils.htmlTrim( wikitext ) .replace( /\r/g, '\n' ) .replace( /\n+/g, '\n' ); } /** * Given a comment and a reply link, add the reply link to its document's DOM tree, at the end of * the comment. * * @param {CommentItem} comment Comment item * @param {HTMLElement} linkNode Reply link */ function addReplyLink( comment, linkNode ) { var target = comment.range.endContainer; // Skip to the end of the "paragraph". This only looks at tag names and can be fooled by CSS, but // avoiding that would be more difficult and slower. while ( target.nextSibling && !( target.nextSibling instanceof HTMLElement && ve.isBlockElement( target.nextSibling ) ) ) { target = target.nextSibling; } // Insert the link before trailing whitespace. // In the MediaWiki parser output,