Generate a role node.

        options : dict
            key value arguments.
        content : content
            content of the directive

        Returns
        -------
        node : docutil Node
            Node generated by the arguments.
505548
def run_role(self, name,
                 options=None,
                 content=None):
        
        if options is None:
            options = {}
        if content is None:
            content = []
        role_fn, _ = role(name,
                          self.language,
                          self.node.line,
                          self.reporter)
        vec, _ = role_fn(name,
                         rawtext=str(content),
                         text=str(content),
                         lineno=self.node.line,
                         inliner=self.memo.inliner,
                         options=options,
                         content=content)
        assert len(vec) == 1, 'only support one list in role'
        return vec[0]
1091537
def make_content_node(channeldir, rel_path, filename, metadata):
    
    file_key, file_ext = os.path.splitext(filename)
    ext = file_ext[1:]
    kind = None
    if ext in content_kinds.MAPPING:
        kind = content_kinds.MAPPING[ext]   # guess what kind based on file extension
    elif 'questions' in metadata:
        kind = content_kinds.EXERCISE
    else:
        raise ValueError('Could not find kind for extension ' + str(ext) + ' in content_kinds.MAPPING')

    # Extract metadata fields
    source_id = metadata.get('source_id', None)
    if source_id is None:
        source_id = metadata['chan_path']

    filepath = os.path.join(rel_path, filename)
    title = metadata['title']
    description = metadata.get('description', None)
    author = metadata.get('author', None)
    lang =  metadata.get('language', None)
    license_dict = metadata.get('license', None)
    thumbnail_chan_path =  metadata.get('thumbnail_chan_path', None)
    if thumbnail_chan_path:
        thumbnail_rel_path = rel_path_from_chan_path(thumbnail_chan_path, channeldir)
    else:
        thumbnail_rel_path = None

    if kind == VIDEO_NODE:
        content_node = dict(
            kind=VIDEO_NODE,
            source_id=source_id,
            title=title,
            author=author,
            description=description,
            language=lang,
            license=license_dict,
            derive_thumbnail=True,  # video-specific option
            thumbnail=thumbnail_rel_path,
            files=[{'file_type':VIDEO_FILE, 'path':filepath, 'language':lang}], # ffmpeg_settings={"crf": 24},
        )

    elif kind == AUDIO_NODE:
        content_node = dict(
            kind=AUDIO_NODE,
            source_id=source_id,
            title=title,
            author=author,
            description=description,
            language=lang,
            license=license_dict,
            thumbnail=thumbnail_rel_path,
            files=[{'file_type':AUDIO_FILE, 'path':filepath, 'language':lang}],
        )

    elif kind == DOCUMENT_NODE:
        content_node = dict(
            kind=DOCUMENT_NODE,
            source_id=source_id,
            title=title,
            author=author,
            description=description,
            language=lang,
            license=license_dict,
            thumbnail=thumbnail_rel_path,
            files=[]
        )
        if ext == 'pdf':
            pdf_file = {
                'file_type':DOCUMENT_FILE,
                'path':filepath,
                'language':lang
            }
            content_node['files'].append(pdf_file)
        elif ext == 'epub':
            epub_file = {
                'file_type':EPUB_FILE,
                'path':filepath,
                'language':lang
            }
            content_node['files'].append(epub_file)
        else:
            raise ValueError('Ext {} not supported for kind {}'.format(ext, kind))

    elif kind == HTML5_NODE:
        content_node = dict(
            kind=HTML5_NODE,
            source_id=source_id,
            title=title,
            author=author,
            description=description,
            language=lang,
            license=license_dict,
            thumbnail=thumbnail_rel_path,
            files=[{'file_type':HTML5_FILE, 'path':filepath, 'language':lang}],
        )

    elif kind == EXERCISE_NODE:
        content_node = dict(
            kind=EXERCISE_NODE,
            source_id=source_id,
            title=title,
            author=author,
            description=description,
            language=lang,
            license=license_dict,
            exercise_data=metadata['exercise_data'],
            questions=metadata['questions'],
            thumbnail=thumbnail_rel_path,
            files=[],
        )

    else:
        raise ValueError('Not implemented case for kind ' + str(kind))

    return content_node
1141456
function insertContentIntoPlaceholder(node, content) {
	const state = {replaced: false};

	node.value = replacePlaceholder(node.value, content, state);
	node.attributes.forEach(attr => {
		if (attr.value) {
			node.setAttribute(attr.name, replacePlaceholder(attr.value, content, state));
		}
	});

	return state.replaced;
}
1373784
def body(self, content):
        
        body = Element('Body', ns=envns)
        body.append(content)
        return body
288351
def get_node(self, role: str, default=None) -> BioCNode:
        
        return next((node for node in self.nodes if node.role == role), default)
1057279
def render_node(node, context=None, edit=True):
    
    output = node.render(**context or {}) or u''
    if edit:
        return u'<span data-i18n="{0}">{1}</span>'.format(node.uri.clone(scheme=None, ext=None, version=None), output)
    else:
        return output
809059
def __gen_node_href(self, layer, node_id):
        
        if istoken(self.dg, node_id):
            base_paula_id = self.paulamap['tokenization']
        else:
            base_paula_id = self.paulamap['hierarchy'][layer]
        return '{0}.xml#{1}'.format(base_paula_id, node_id)
1119290
def add_role(self, role_obj):
        
        role_node = role_obj.get_node()
        self.node.append(role_node)
67
def get_html_content(self):
        

        # Extract full element node content (including subelements)
        html_content = ''
        if hasattr(self, 'xml_element'):
            xml = self.xml_element
            content_list = ["" if xml.text is None else xml.text]

            def to_string(xml):
                if isinstance(xml, _Comment):
                    return str(xml)
                else:
                    return ElementTree.tostring(xml).decode('utf-8')

            content_list += [to_string(e) for e in xml.getchildren()]

            full_xml_content = "".join(content_list)

            # Parse tags to generate HTML valid content
            first_regex = r'html:'
            second_regex = r' xmlns:html=(["\'])(?:(?=(\\?))\2.)*?\1'
            html_content = re.sub(first_regex, '',
                                  re.sub(second_regex, '', full_xml_content))

        return html_content
194363
function(node){
    var child = node.firstChild;
    return !(child && child.nodeType == 1) && !(node.innerText || node.textContent || '').length;
  }
61507
def render_node(self):
        
        self.content = self.node.nodelist.render(self.context)
991660
def nodes_with_role(rolename):
    """"""
    nodes = [n['name'] for n in
             lib.get_nodes_with_role(rolename, env.chef_environment)]
    if not len(nodes):
        print("No nodes found with role '{0}'".format(rolename))
        sys.exit(0)
    return node(*nodes)
1313905
function (namespaceURI, qualifiedName, doctype) {
        return Node.createDocument({
            name: qualifiedName,
            namespaceURI: namespaceURI,
            doctype: doctype
        });
    }
297667
def _generate_ids(self, document, content):
        
        existing_ids = content.xpath('//*/@id')
        elements = [
            'p', 'dl', 'dt', 'dd', 'table', 'div', 'section', 'figure',
            'blockquote', 'q', 'code', 'pre', 'object', 'img', 'audio',
            'video',
            ]
        elements_xpath = '|'.join(['.//{}|.//xhtml:{}'.format(elem, elem)
                                  for elem in elements])

        data_types = [
            'equation', 'list', 'exercise', 'rule', 'example', 'note',
            'footnote-number', 'footnote-ref', 'problem', 'solution', 'media',
            'proof', 'statement', 'commentary'
            ]
        data_types_xpath = '|'.join(['.//*[@data-type="{}"]'.format(data_type)
                                     for data_type in data_types])

        xpath = '|'.join([elements_xpath, data_types_xpath])

        mapping = {}  # old id -> new id

        for node in content.xpath(xpath, namespaces=HTML_DOCUMENT_NAMESPACES):
            old_id = node.attrib.get('id')
            document_id = document.id.replace('_', '')
            if old_id:
                new_id = 'auto_{}_{}'.format(document_id, old_id)
            else:
                random_number = random.randint(0, 100000)
                new_id = 'auto_{}_{}'.format(document_id, random_number)
            while new_id in existing_ids:
                random_number = random.randint(0, 100000)
                new_id = 'auto_{}_{}'.format(document_id, random_number)
            node.attrib['id'] = new_id
            if old_id:
                mapping[old_id] = new_id
            existing_ids.append(new_id)

        for a in content.xpath('//a[@href]|//xhtml:a[@href]',
                               namespaces=HTML_DOCUMENT_NAMESPACES):
            href = a.attrib['href']
            if href.startswith('#') and href[1:] in mapping:
                a.attrib['href'] = '#{}'.format(mapping[href[1:]])
253131
def lsst_doc_shortlink_role(name, rawtext, text, lineno, inliner,
                            options=None, content=None):
    
    options = options or {}
    content = content or []
    node = nodes.reference(
        text='{0}-{1}'.format(name.upper(), text),
        refuri='https://ls.st/{0}-{1}'.format(name, text),
        **options)
    return [node], []
991922
def newTextLen(content, len):
    
    ret = libxml2mod.xmlNewTextLen(content, len)
    if ret is None:raise treeError('xmlNewTextLen() failed')
    return xmlNode(_obj=ret)
979353
def add_xml_to_node(self, node):
        
        # pylint: disable=E1101
        # Set node.tag based on our class name.
        node.tag = self.xml_element_name()
        node.set('xblock-family', self.entry_point)

        # Set node attributes based on our fields.
        for field_name, field in self.fields.items():
            if field_name in ('children', 'parent', 'content'):
                continue
            if field.is_set_on(self) or field.force_export:
                self._add_field(node, field_name, field)

        # A content field becomes text content.
        text = self.xml_text_content()
        if text is not None:
            node.text = text