Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!takemy.news.telefonica.de!telefonica.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1957237.G35ZFXocOO@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sat, 22 Feb 2014 23:32:17 +0100 User-Agent: KNode/4.11.5 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <2186233.TZ7MnjCRox@PointedEars.de> MIME-Version: 1.0 Lines: 79 NNTP-Posting-Date: 22 Feb 2014 23:32:19 CET NNTP-Posting-Host: 3d83f28c.newsspool1.arcor-online.net X-Trace: DXC=:f_bHeE0T7mic==]BZ:afn4Fo<]lROoRankgeX?EC@@`\BGGOn[Md>hDZm8W4\YJNlYUVHKH;GI^g>8ZdD_1a;VhaU]>SjG;@Sh X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:23210 Cezary Tomczyk wrote: > Thomas 'PointedEars' Lahn wrote: >> Cezary Tomczyk wrote: >>> To get inner text of HTML element I've been using: >>> >>> function get_inner_text(node) { >>> if (node.nodeType === 3) { >>> return node.data; >>> } >>> >>> var txt = ''; >>> >>> node = node.firstChild; >>> while (node) { >>> txt += get_inner_text(node); >>> node = node.nextSibling; >>> } >>> return txt.replace(/\s+/g, ' '); >> ^^^^^^^^^^^^^^^^^^^^^^^^ >> This is _not_ equivalent to node.textContent, see >> . > > I see. In documentation I've read that "No whitespace normalization is > performed and the returned string does not contain the white spaces in > element content[...]." > > As for "whitespace normalization" I found that it's about "(spaces, > tabs, and blank lines)" (http://www.w3.org/TR/REC-xml/#sec-white-space). > However, "blank lines" means "new line" using \r\n or \r or \n, right? > > Also, how "whitespace normalization" should work? E.g. replacing " " > to " "? RTFSpec. However, since it says there that “*no* whitespace normalization is performed” with “textContent”, you do not have to concern yourself with that in “textContent” emulation. However, ISTM that at least Chromium “Version 32.0.1700.123 Debian jessie/sid (248368)” does not implement “textContent” as specified: “the returned string does not (read: MUST NOT) contain the white spaces in element content (read: “element content whitespace” as per XML), but it does there. With var div = document.createElement("div"); div.appendChild(document.createTextNode(" ")); var span = document.createElement("span"); span.appendChild(document.createTextNode(" ")); div.appendChild(span); “div.textContent” yields four spaces there, but IIUC should yield only two because the whitespace preceding the “span” element would be “element content whitespace” per XML. The reason for that may be that the first child object implements the Text interface of DOM Level 3 Core only incompletely: it implements the splitText() method introduced in Level 1 Core, and the “wholeText” attribute and replaceWholeText() method introduced in Level 3 Core; but it does not implement the “isElementContentWhitespace” attribute also introduced in the latter Specification. > Any suggestions? Yes. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.