<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://bsd.neuroinf.jp/w/index.php?action=history&amp;feed=atom&amp;title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%3AHTMLParser%2FElementNode</id>
	<title>モジュール:HTMLParser/ElementNode - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://bsd.neuroinf.jp/w/index.php?action=history&amp;feed=atom&amp;title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%3AHTMLParser%2FElementNode"/>
	<link rel="alternate" type="text/html" href="https://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:HTMLParser/ElementNode&amp;action=history"/>
	<updated>2026-04-15T12:08:09Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:HTMLParser/ElementNode&amp;diff=44214&amp;oldid=prev</id>
		<title>WikiSysop: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:HTMLParser/ElementNode&amp;diff=44214&amp;oldid=prev"/>
		<updated>2020-07-13T01:10:36Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2020年7月13日 (月) 10:10時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;diff-notice&quot; lang=&quot;ja&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(相違点なし)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wiki-mw_:diff:1.41:old-44213:rev-44214 --&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:HTMLParser/ElementNode&amp;diff=44213&amp;oldid=prev</id>
		<title>bsd&gt;Rillke: ←Created page with &#039;-- Derivative work of:  --[[ 	(The MIT license) 	Copyright (c) 2013, Wouter Scherphof (wouter.scherphof@gmail.com) 	Permission is hereby granted, free of charge...&#039;</title>
		<link rel="alternate" type="text/html" href="https://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:HTMLParser/ElementNode&amp;diff=44213&amp;oldid=prev"/>
		<updated>2013-11-21T13:17:13Z</updated>

		<summary type="html">&lt;p&gt;&lt;a href=&quot;/w/index.php?title=COM:AES&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;COM:AES (存在しないページ)&quot;&gt;←&lt;/a&gt;Created page with &amp;#039;-- Derivative work of:  --[[ 	(The MIT license) 	Copyright (c) 2013, Wouter Scherphof (wouter.scherphof@gmail.com) 	Permission is hereby granted, free of charge...&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- Derivative work of:&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
	(The MIT license)&lt;br /&gt;
	Copyright (c) 2013, Wouter Scherphof (wouter.scherphof@gmail.com)&lt;br /&gt;
	Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &amp;quot;Software&amp;quot;), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:&lt;br /&gt;
	The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.&lt;br /&gt;
	THE SOFTWARE IS PROVIDED &amp;quot;AS IS&amp;quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.&lt;br /&gt;
--]]&lt;br /&gt;
 &lt;br /&gt;
-- Source: https://github.com/wscherphof/lua-htmlparser/tree/master/src/htmlparser&lt;br /&gt;
&lt;br /&gt;
local Set = require(&amp;quot;Module:Set&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
local ElementNode = {}&lt;br /&gt;
ElementNode.mt = {__index = ElementNode}&lt;br /&gt;
function ElementNode:new(nameortext, node, descend, openstart, openend)&lt;br /&gt;
  local instance = {&lt;br /&gt;
    name = nameortext,&lt;br /&gt;
    level = 0,&lt;br /&gt;
    parent = nil,&lt;br /&gt;
    root = nil,&lt;br /&gt;
    nodes = {},&lt;br /&gt;
    _openstart = openstart, _openend = openend,&lt;br /&gt;
    _closestart = openstart, _closeend = openend,&lt;br /&gt;
    attributes = {},&lt;br /&gt;
    id = nil,&lt;br /&gt;
    classes = {},&lt;br /&gt;
    deepernodes = Set:new(),&lt;br /&gt;
    deeperelements = {}, deeperattributes = {}, deeperids = {}, deeperclasses = {}&lt;br /&gt;
  }&lt;br /&gt;
  if not node then&lt;br /&gt;
    instance.name = &amp;quot;root&amp;quot;&lt;br /&gt;
    instance.root = instance&lt;br /&gt;
    instance._text = nameortext&lt;br /&gt;
    local length = string.len(nameortext)&lt;br /&gt;
    instance._openstart, instance._openend = 1, length&lt;br /&gt;
    instance._closestart, instance._closeend = 1, length&lt;br /&gt;
  elseif descend then&lt;br /&gt;
    instance.root = node.root&lt;br /&gt;
    instance.parent = node&lt;br /&gt;
    instance.level = node.level + 1&lt;br /&gt;
    table.insert(node.nodes, instance)&lt;br /&gt;
  else&lt;br /&gt;
    instance.root = node.root&lt;br /&gt;
    instance.parent = node.parent&lt;br /&gt;
    instance.level = node.level&lt;br /&gt;
    table.insert(node.parent.nodes, instance)&lt;br /&gt;
  end&lt;br /&gt;
  return setmetatable(instance, ElementNode.mt)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ElementNode:gettext()&lt;br /&gt;
  return string.sub(self.root._text, self._openstart, self._closeend)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ElementNode:getcontent()&lt;br /&gt;
  return string.sub(self.root._text, self._openend + 1, self._closestart - 1)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ElementNode:addattribute(k, v)&lt;br /&gt;
  self.attributes[k] = v&lt;br /&gt;
  if string.lower(k) == &amp;quot;id&amp;quot; then&lt;br /&gt;
    self.id = v&lt;br /&gt;
  -- class attribute contains &amp;quot;space-separated tokens&amp;quot;, each of which we&amp;#039;d like quick access to&lt;br /&gt;
  elseif string.lower(k) == &amp;quot;class&amp;quot; then&lt;br /&gt;
    for class in string.gmatch(v, &amp;quot;%S+&amp;quot;) do&lt;br /&gt;
      table.insert(self.classes, class)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function insert(table, name, node)&lt;br /&gt;
  table[name] = table[name] or Set:new()&lt;br /&gt;
  table[name]:add(node)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ElementNode:close(closestart, closeend)&lt;br /&gt;
  if closestart and closeend then&lt;br /&gt;
    self._closestart, self._closeend = closestart, closeend&lt;br /&gt;
  end&lt;br /&gt;
  -- inform hihger level nodes about this element&amp;#039;s existence in their branches&lt;br /&gt;
  local node = self&lt;br /&gt;
  while true do&lt;br /&gt;
    node = node.parent&lt;br /&gt;
    if not node then break end&lt;br /&gt;
    node.deepernodes:add(self)&lt;br /&gt;
    insert(node.deeperelements, self.name, self)&lt;br /&gt;
    for k in pairs(self.attributes) do&lt;br /&gt;
      insert(node.deeperattributes, k, self)&lt;br /&gt;
    end&lt;br /&gt;
    if self.id then&lt;br /&gt;
      insert(node.deeperids, self.id, self)&lt;br /&gt;
    end&lt;br /&gt;
    for _,v in ipairs(self.classes) do&lt;br /&gt;
      insert(node.deeperclasses, v, self)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function escape(s)&lt;br /&gt;
  -- escape all ^, $, (, ), %, ., [, ], *, +, - , and ? with a % prefix&lt;br /&gt;
  return string.gsub(s, &amp;quot;([%^%$%(%)%%%.%[%]%*%+%-%?])&amp;quot;, &amp;quot;%%&amp;quot; .. &amp;quot;%1&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function select(self, s)&lt;br /&gt;
  if not s or type(s) ~= &amp;quot;string&amp;quot; or s == &amp;quot;&amp;quot; then return Set:new() end&lt;br /&gt;
  local sets = {[&amp;quot;&amp;quot;] = self.deeperelements, [&amp;quot;[&amp;quot;] = self.deeperattributes,&lt;br /&gt;
                [&amp;quot;#&amp;quot;] = self.deeperids, [&amp;quot;.&amp;quot;] = self.deeperclasses}&lt;br /&gt;
  local function match(t, w)&lt;br /&gt;
    local m, e, v&lt;br /&gt;
    if t == &amp;quot;[&amp;quot; then w, m, e, v = string.match(w,&lt;br /&gt;
        &amp;quot;([^=|%*~%$!%^]+)&amp;quot; .. -- w = 1 or more characters up to a possible &amp;quot;=&amp;quot;, &amp;quot;|&amp;quot;, &amp;quot;*&amp;quot;, &amp;quot;~&amp;quot;, &amp;quot;$&amp;quot;, &amp;quot;!&amp;quot;, or &amp;quot;^&amp;quot;&lt;br /&gt;
        &amp;quot;([|%*~%$!%^]?)&amp;quot; .. -- m = an optional &amp;quot;|&amp;quot;, &amp;quot;*&amp;quot;, &amp;quot;~&amp;quot;, &amp;quot;$&amp;quot;, &amp;quot;!&amp;quot;, or &amp;quot;^&amp;quot;, preceding the optional &amp;quot;=&amp;quot;&lt;br /&gt;
        &amp;quot;(=?)&amp;quot; .. -- e = the optional &amp;quot;=&amp;quot;&lt;br /&gt;
        &amp;quot;(.*)&amp;quot; -- v = anything following the &amp;quot;=&amp;quot;, or else &amp;quot;&amp;quot;&lt;br /&gt;
      )&lt;br /&gt;
    end&lt;br /&gt;
    local matched = Set:new(sets[t][w])&lt;br /&gt;
    -- attribute value selectors&lt;br /&gt;
    if e == &amp;quot;=&amp;quot; then&lt;br /&gt;
      if #v &amp;lt; 2 then v = &amp;quot;&amp;#039;&amp;quot; .. v .. &amp;quot;&amp;#039;&amp;quot; end -- values should be quoted&lt;br /&gt;
      v = string.sub(v, 2, #v - 1) -- strip quotes&lt;br /&gt;
      if m == &amp;quot;!&amp;quot; then matched = Set:new(self.deepernodes) end -- include those without that attribute&lt;br /&gt;
      for node in pairs(matched) do&lt;br /&gt;
        local a = node.attributes[w]&lt;br /&gt;
        -- equals&lt;br /&gt;
        if m == &amp;quot;&amp;quot; and a ~= v then matched:remove(node)&lt;br /&gt;
        -- not equals&lt;br /&gt;
        elseif m == &amp;quot;!&amp;quot; and a == v then matched:remove(node)&lt;br /&gt;
        -- prefix&lt;br /&gt;
        elseif m ==&amp;quot;|&amp;quot; and string.match(a, &amp;quot;^[^-]*&amp;quot;) ~= v then matched:remove(node)&lt;br /&gt;
        -- contains&lt;br /&gt;
        elseif m ==&amp;quot;*&amp;quot; and string.match(a, escape(v)) ~= v then matched:remove(node)&lt;br /&gt;
        -- word&lt;br /&gt;
        elseif m ==&amp;quot;~&amp;quot; then matched:remove(node)&lt;br /&gt;
          for word in string.gmatch(a, &amp;quot;%S+&amp;quot;) do&lt;br /&gt;
            if word == v then matched:add(node) break end&lt;br /&gt;
          end&lt;br /&gt;
        -- starts with&lt;br /&gt;
        elseif m ==&amp;quot;^&amp;quot; and string.match(a, &amp;quot;^&amp;quot; .. escape(v)) ~= v then matched:remove(node)&lt;br /&gt;
        -- ends with&lt;br /&gt;
        elseif m ==&amp;quot;$&amp;quot; and string.match(a, escape(v) .. &amp;quot;$&amp;quot;) ~= v then matched:remove(node)&lt;br /&gt;
        end&lt;br /&gt;
      end -- for node&lt;br /&gt;
    end -- if v&lt;br /&gt;
    return matched&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  local subjects, resultset, childrenonly = Set:new({self})&lt;br /&gt;
  for part in string.gmatch(s, &amp;quot;%S+&amp;quot;) do&lt;br /&gt;
    if part == &amp;quot;&amp;gt;&amp;quot; then&lt;br /&gt;
    	childrenonly = true&lt;br /&gt;
    	-- Next part&lt;br /&gt;
    else&lt;br /&gt;
	    resultset = Set:new()&lt;br /&gt;
	    for subject in pairs(subjects) do&lt;br /&gt;
	      local star = subject.deepernodes&lt;br /&gt;
	      if childrenonly then star = Set:new(subject.nodes) end&lt;br /&gt;
	      resultset = resultset + star&lt;br /&gt;
	    end&lt;br /&gt;
	    childrenonly = false&lt;br /&gt;
	    if part == &amp;quot;*&amp;quot; then&lt;br /&gt;
	    	-- Next part&lt;br /&gt;
	    else&lt;br /&gt;
		    local excludes, filter = Set:new()&lt;br /&gt;
		    for t, w in string.gmatch(part,&lt;br /&gt;
		      &amp;quot;([:%[#.]?)&amp;quot; .. -- t = an optional :, [, #, or .&lt;br /&gt;
		      &amp;quot;([^:%(%[#.%]%)]+)&amp;quot; .. -- w = 1 or more of anything not :, (, [, #, ., ], or )&lt;br /&gt;
		      &amp;quot;%]?%)?&amp;quot; -- followed by an uncaptured optional ] and/or )&lt;br /&gt;
		    ) do&lt;br /&gt;
		      if t == &amp;quot;:&amp;quot; then&lt;br /&gt;
		      	filter = w &lt;br /&gt;
		      	-- nextw&lt;br /&gt;
		      else &lt;br /&gt;
			      local matched = match(t, w)&lt;br /&gt;
			      if filter == &amp;quot;not&amp;quot; then&lt;br /&gt;
			        excludes = excludes + matched&lt;br /&gt;
			      else&lt;br /&gt;
			        resultset = resultset * matched&lt;br /&gt;
			      end&lt;br /&gt;
			      filter = nil&lt;br /&gt;
			  end&lt;br /&gt;
		    end&lt;br /&gt;
		    resultset = resultset - excludes&lt;br /&gt;
		    subjects = Set:new(resultset)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
  end&lt;br /&gt;
  return resultset&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ElementNode:select(s) return select(self, s) end&lt;br /&gt;
ElementNode.mt.__call = select&lt;br /&gt;
&lt;br /&gt;
return ElementNode&lt;/div&gt;</summary>
		<author><name>bsd&gt;Rillke</name></author>
	</entry>
</feed>