사용자:하늘/루아

< 사용자:하늘
하늘 (토론 | 기여)님의 2021년 3월 26일 (금) 17:07 판

HTML library

mw.html is a fluent interface for building complex HTML from Lua. A mw.html object can be created using [[<tvar|anchor>#mw.html.create</>|mw.html.create]]. </translate>

틀:Anchor <translate> Functions documented as mw.html.name are available on the global mw.html table; functions documented as mw.html:name and html:name are methods of an mw.html object (see [[<tvar|anchor>#mw.html.create</>|mw.html.create]]).

A basic example could look like this: </translate>

local div = mw.html.create( 'div' )
div
     :attr( 'id', 'testdiv' )
     :css( 'width', '100%' )
     :wikitext( 'Some text' )
     :tag( 'hr' )
return tostring( div )
-- Output: <div id="testdiv" style="width:100%;">Some text<hr /></div>

mw.html.create

태그 생성 <translate> mw.html.create( tagName, args )</translate>

<translate> Creates a new mw.html object containing a tagName html element. You can also pass an empty string or nil as tagName in order to create an empty mw.html object.

args can be a table with the following keys:

  • args.selfClosing: Force the current tag to be self-closing, even if mw.html doesn't recognize it as self-closing
  • args.parent: Parent of the current mw.html instance (intended for internal usage)

</translate>

mw.html:node

<translate> html:node( builder )</translate>

<translate> Appends a child mw.html (builder) node to the current mw.html instance. If a nil parameter is passed, this is a no-op. A (builder) node is a string representation of an html element. </translate>

mw.html:wikitext

텍스트 출력? html:wikitext( ... )

<translate> Appends an undetermined number of wikitext strings to the mw.html object.

Note that this stops at the first nil item. </translate>

mw.html:newline

새로운 행 html:newline()

<translate> Appends a newline to the mw.html object. </translate>

mw.html:tag

자식노드 삽입 <translate> html:tag( tagName, args )</translate>

<translate> Appends a new child node with the given tagName to the builder, and returns a mw.html instance representing that new node. The args parameter is identical to that of [[<tvar|anchor>#mw.html.create</>|mw.html.create]] </translate>

mw.html:attr

<translate> html:attr( name, value )</translate>
<translate> html:attr( table )</translate>

<translate> Set an HTML attribute with the given name and value on the node. Alternatively a table holding name->value pairs of attributes to set can be passed. In the first form, a value of nil causes any attribute with the given name to be unset if it was previously set. </translate>

mw.html:getAttr

<translate> html:getAttr( name )</translate>

<translate> Get the value of a html attribute previously set using [[<tvar|anchor>#mw.html:attr</>|html:attr()]] with the given name. </translate>

mw.html:addClass

<translate> html:addClass( class )</translate>

<translate> Adds a class name to the node's class attribute. If a nil parameter is passed, this is a no-op. </translate>

mw.html:css

<translate> html:css( name, value )</translate>
<translate> html:css( table )</translate>

<translate> Set a CSS property with the given name and value on the node. Alternatively a table holding name->value pairs of properties to set can be passed. In the first form, a value of nil causes any property with the given name to be unset if it was previously set. </translate>

mw.html:cssText

<translate> html:cssText( css )</translate>

<translate> Add some raw css to the node's style attribute. If a nil parameter is passed, this is a no-op. </translate>

mw.html:done

html:done()

<translate> Returns the parent node under which the current node was created. Like jQuery.end, this is a convenience function to allow the construction of several child nodes to be chained together into a single statement. </translate>

mw.html:allDone

html:allDone()

<translate> Like [[<tvar|anchor>#mw.html:done</>|html:done()]], but traverses all the way to the root node of the tree and returns it.