Create a Slate Raw text node.
483326
function createText(value, data) {
  const node = { object: 'text', data };
  const leaves = isArray(value) ? value : [{ text: value }];
  return { ...node, leaves };
}
104024
function generateTableRowNode(line, separator) {

    const tableRow = {
        type: 'TableRow',
        children: separator.map(align => ({
            type: 'TableDataCell',
            align
        }))
    };

    for (let i = 0, data = calRow(line), len = data.length; i < len; i++) {
        tableRow.children[i].rawValue = data[i];
    }

    return tableRow;

}
1006534
def append_text(self, content):
        
        if content.node.hasText():
            content.text = content.node.getText()
50157
function convertNode(node, nodes) {
  switch (node.type) {
    /**
     * General
     *
     * Convert simple cases that only require a type and children, with no
     * additional properties.
     */
    case 'root':
    case 'paragraph':
    case 'listItem':
    case 'blockquote':
    case 'tableRow':
    case 'tableCell': {
      return createBlock(typeMap[node.type], nodes);
    }

    /**
     * Shortcodes
     *
     * Shortcode nodes are represented as "void" blocks in the Slate AST. They
     * maintain the same data as MDAST shortcode nodes. Slate void blocks must
     * contain a blank text node.
     */
    case 'shortcode': {
      const { data } = node;
      const nodes = [createText('')];
      return createBlock(typeMap[node.type], nodes, { data, isVoid: true });
    }

    /**
     * Text
     *
     * Text and HTML nodes are both used to render text, and should be treated
     * the same. HTML is treated as text because we never want to escape or
     * encode it.
     */
    case 'text':
    case 'html': {
      return createText(node.value, node.data);
    }

    /**
     * Inline Code
     *
     * Inline code nodes from an MDAST are represented in our Slate schema as
     * text nodes with a "code" mark. We manually create the "leaf" containing
     * the inline code value and a "code" mark, and place it in an array for use
     * as a Slate text node's children array.
     */
    case 'inlineCode': {
      const leaf = {
        text: node.value,
        marks: [{ type: 'code' }],
      };
      return createText([leaf]);
    }

    /**
     * Marks
     *
     * Marks are typically decorative sub-types that apply to text nodes. In an
     * MDAST, marks are nodes that can contain other nodes. This nested
     * hierarchy has to be flattened and split into distinct text nodes with
     * their own set of marks.
     */
    case 'strong':
    case 'emphasis':
    case 'delete': {
      return convertMarkNode(node);
    }

    /**
     * Headings
     *
     * MDAST headings use a single type with a separate "depth" property to
     * indicate the heading level, while the Slate schema uses a separate node
     * type for each heading level. Here we get the proper Slate node name based
     * on the MDAST node depth.
     */
    case 'heading': {
      const depthMap = { 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six' };
      const slateType = `heading-${depthMap[node.depth]}`;
      return createBlock(slateType, nodes);
    }

    /**
     * Code Blocks
     *
     * MDAST code blocks are a distinct node type with a simple text value. We
     * convert that value into a nested child text node for Slate. We also carry
     * over the "lang" data property if it's defined.
     */
    case 'code': {
      const data = { lang: node.lang };
      const text = createText(node.value);
      const nodes = [text];
      return createBlock(typeMap[node.type], nodes, { data });
    }

    /**
     * Lists
     *
     * MDAST has a single list type and an "ordered" property. We derive that
     * information into the Slate schema's distinct list node types. We also
     * include the "start" property, which indicates the number an ordered list
     * starts at, if defined.
     */
    case 'list': {
      const slateType = node.ordered ? 'numbered-list' : 'bulleted-list';
      const data = { start: node.start };
      return createBlock(slateType, nodes, { data });
    }

    /**
     * Breaks
     *
     * MDAST soft break nodes represent a trailing double space or trailing
     * slash from a Markdown document. In Slate, these are simply transformed to
     * line breaks within a text node.
     */
    case 'break': {
      const textNode = createText('\n');
      return createInline('break', {}, [textNode]);
    }

    /**
     * Thematic Breaks
     *
     * Thematic breaks are void nodes in the Slate schema.
     */
    case 'thematicBreak': {
      return createBlock(typeMap[node.type], { isVoid: true });
    }

    /**
     * Links
     *
     * MDAST stores the link attributes directly on the node, while our Slate
     * schema references them in the data object.
     */
    case 'link': {
      const { title, url, data } = node;
      const newData = { ...data, title, url };
      return createInline(typeMap[node.type], { data: newData }, nodes);
    }

    /**
     * Images
     *
     * Identical to link nodes except for the lack of child nodes and addition
     * of alt attribute data MDAST stores the link attributes directly on the
     * node, while our Slate schema references them in the data object.
     */
    case 'image': {
      const { title, url, alt, data } = node;
      const newData = { ...data, title, alt, url };
      return createInline(typeMap[node.type], { isVoid: true, data: newData });
    }

    /**
     * Tables
     *
     * Tables are parsed separately because they may include an "align"
     * property, which should be passed to the Slate node.
     */
    case 'table': {
      const data = { align: node.align };
      return createBlock(typeMap[node.type], nodes, { data });
    }
  }
}
1107340
def node_text( value, block = nil )
      @seq_map = false
      valx = value.dup
      unless block
        block =
          if options(:UseBlock)
            '|'
          elsif not options(:UseFold) and valx =~ /\n[ \t]/ and not valx =~ /#{YAML::ESCAPE_CHAR}/
            '|'
          else
            '>'
          end
        indt = $&.to_i if block =~ /\d+/
        if valx =~ /(\A\n*[ \t#]|^---\s+)/
          indt = options(:Indent) unless indt.to_i > 0
          block += indt.to_s
        end

        block +=
          if valx =~ /\n\Z\n/
            "+"
          elsif valx =~ /\Z\n/
            ""
          else
            "-"
          end
      end
      block += "\n"
      if block[0] == ?"
        esc_skip = ( "\t\n" unless valx =~ /^[ \t]/ ) || ""
        valx = fold( YAML::escape( valx, esc_skip ) + "\"" ).chomp
        self << '"' + indent_text( valx, indt, false )
      else
        if block[0] == ?>
          valx = fold( valx )
        end
        #p [block, indt]
        self << block + indent_text( valx, indt )
      end
    end
829771
def serialize_paragraph(ctx, document, par, root, embed=True):
    

    style = get_style(document, par)

    elem = etree.Element('p')

    if ctx.options['embed_styles']:
        _style = get_style_css(ctx, par)

        if _style != '':
            elem.set('style', _style)

    else:
        _style = ''

    if style:
        elem.set('class', get_css_classes(document, style))

    max_font_size = get_style_fontsize(par)

    if style:
        max_font_size = _get_font_size(document, style)

    for el in par.elements:
        _serializer =  ctx.get_serializer(el)

        if _serializer:
            _serializer(ctx, document, el, elem)

        if isinstance(el, doc.Text):
            children = list(elem)
            _text_style = get_style_css(ctx, el)
            _text_class = el.rpr.get('style', '').lower()

            if _text_class == '':
                __s = get_style(document, par)
                if __s is not None:
                    _text_class = get_style_name(__s).lower()

            if get_style_fontsize(el) > max_font_size:
                max_font_size = get_style_fontsize(el)

            if 'superscript' in el.rpr:
                new_element = etree.Element('sup')
                new_element.text = el.value()
            elif 'subscript' in el.rpr:
                new_element = etree.Element('sub')
                new_element.text = el.value()               
            elif 'b' in el.rpr or 'i' in el.rpr or 'u' in el.rpr:                
                new_element = None
                _element = None

                def _add_formatting(f, new_element, _element):
                    if f in el.rpr:
                        _t = etree.Element(f)

                        if new_element is not None:
                            _element.append(_t)
                            _element = _t
                        else:
                            new_element = _t
                            _element = new_element

                    return new_element, _element

                new_element, _element = _add_formatting('b', new_element, _element)
                new_element, _element = _add_formatting('i', new_element, _element)
                new_element, _element = _add_formatting('u', new_element, _element)
                
                _element.text = el.value()

                for comment_id in ctx.opened_comments:
                    document.comments[comment_id].text += ' ' + el.value()
            else:
                new_element = etree.Element('span')
                new_element.text = el.value()
                if ctx.options['embed_styles']:
                    try:
                        new_element.set('class', _text_class)
                    except:
                        pass

                for comment_id in ctx.opened_comments:
                    if comment_id in document.comments:
                        document.comments[comment_id].text += ' ' + el.value()

            if ctx.options['embed_styles']:
                if _text_style != '' and _style != _text_style:
                    new_element.set('style', _text_style)

            # This is for situations when style has options and
            # text is trying to unset them
            # else:            
            #     new_element.set('class', 'noformat')

            was_inserted = False

            if len(children) > 0:
                _child_style = children[-1].get('style') or ''
                _child_class = children[-1].get('class', '')

                if new_element.tag == children[-1].tag and ((_text_class == _child_class or _child_class == '') and (_text_style == _child_style or _child_style == '')) and children[-1].tail is None:
                    txt = children[-1].text or ''
                    txt2 = new_element.text or ''
                    children[-1].text = u'{}{}'.format(txt, txt2)  
                    was_inserted = True

                if not was_inserted:
                    if _style == _text_style  and new_element.tag == 'span' and (_text_class == _child_class or _child_class == ''):
                        _e = children[-1]

                        txt = _e.tail or ''
                        _e.tail = u'{}{}'.format(txt, new_element.text)
                        was_inserted = True
  
                    if not was_inserted and new_element.tag == 'span' and (_text_class != _child_class):
                        _e = children[-1]
                        txt = _e.tail or ''
                        _e.tail = u'{}{}'.format(txt, new_element.text)
                        was_inserted = True       

            if not was_inserted:
                _child_class = new_element.get('class', '')
                try:
                    _child_class = children[-1].get('class', '')
                except:
                    _child_class = ''

                if _style ==  _text_style  and new_element.tag == 'span' and (_text_class == _child_class):
                    txt = elem.text or ''
                    elem.text = u'{}{}'.format(txt, new_element.text)
                else:
                    if new_element.text != u'':
                        elem.append(new_element)
    
    if not par.is_dropcap() and par.ilvl == None:
        if style:
            if ctx.header.is_header(par, max_font_size, elem, style=style):
                elem.tag = ctx.header.get_header(par, style, elem)
                if par.ilvl == None:        
                    root = close_list(ctx, root)
                    ctx.ilvl, ctx.numid = None, None

                if root is not None:
                    root.append(elem)

                fire_hooks(ctx, document, par, elem, ctx.get_hook('h'))
                return root
        else:
#            Commented part where we only checked for heading if font size
#            was bigger than default font size. In many cases this did not
#            work out well.
#            if max_font_size > ctx.header.default_font_size:
            if True:
                if ctx.header.is_header(par, max_font_size, elem, style=style):
                    if elem.text != '' and len(list(elem)) != 0:
                        elem.tag = ctx.header.get_header(par, max_font_size, elem)

                        if par.ilvl == None:        
                            root = close_list(ctx, root)
                            ctx.ilvl, ctx.numid = None, None


                        if root is not None:
                            root.append(elem)

                        fire_hooks(ctx, document, par, elem, ctx.get_hook('h'))
                        return root

    if len(list(elem)) == 0 and elem.text is None:
        if ctx.options['empty_paragraph_as_nbsp']:
            elem.append(etree.Entity('nbsp'))

    # Indentation is different. We are starting or closing list.
    if par.ilvl != None:        
        root = open_list(ctx, document, par, root, elem)
        return root
    else:
        root = close_list(ctx, root)
        ctx.ilvl, ctx.numid = None, None

    # Add new elements to our root element.
    if root is not None:
        root.append(elem)

    fire_hooks(ctx, document, par, elem, ctx.get_hook('p'))

    return root
1329803
def gen_text(env: TextIOBase, package: str, tmpl: str):
    """"""
    if env:
        env_args = json_datetime.load(env)
    else:
        env_args = {}
    jinja_env = template.setup(package)
    echo(jinja_env.get_template(tmpl).render(**env_args))
817415
def build_paragraph(content, hard_breaks=False):
  
  lines = list(filter(None, [line.strip() for line in content.split('\n')]))
  if hard_breaks:
    for line_number in range(len(lines) - 1):
      lines[line_number] = "{}<br />".format(lines[line_number])
  return "<p>{}</p>".format('\n'.join(lines))
878600
def to_text(self, tree, force_root=False):
        

        self.extract_tag_metadata(tree)

        text = []
        attributes = []
        comments = []
        blocks = []

        if not (self.ignores.match(tree) if self.ignores else None):
            # The root of the document is the BeautifulSoup object
            capture = self.captures.match(tree) if self.captures is not None else None
            # Check attributes for normal tags
            if capture:
                for attr in self.attributes:
                    value = tree.attrs.get(attr, '').strip()
                    if value:
                        sel = self.construct_selector(tree, attr=attr)
                        attributes.append((value, sel))

            # Walk children
            for child in tree.children:
                string = str(child).strip()
                is_comment = isinstance(child, bs4.Comment)
                if isinstance(child, bs4.element.Tag):
                    t, b, a, c = self.to_text(child)
                    text.extend(t)
                    attributes.extend(a)
                    comments.extend(c)
                    blocks.extend(b)
                # Get content if not the root and not a comment (unless we want comments).
                elif not isinstance(child, NON_CONTENT) and (not is_comment or self.comments):
                    string = str(child).strip()
                    if string:
                        if is_comment:
                            sel = self.construct_selector(tree) + '<!--comment-->'
                            comments.append((string, sel))
                        elif capture:
                            text.append(string)
                            text.append(' ')
        elif self.comments:
            for child in tree.descendants:
                if isinstance(child, bs4.Comment):
                    string = str(child).strip()
                    if string:
                        sel = self.construct_selector(tree) + '<!--comment-->'
                        comments.append((string, sel))

        text = self.store_blocks(tree, blocks, text, force_root)

        if tree.parent is None or force_root:
            return blocks, attributes, comments
        else:
            return text, blocks, attributes, comments
717480
def copy_node(node):
    """"""
    element = node.makeelement(node.tag)
    element.text = node.text
    element.tail = node.tail
    for key, value in node.items():
        element.set(key, value)

    return element
1081437
function processTextNode(node, options) {
    options = options || {};

    var data = [].concat(getBasicFields(node, options)).
        concat([
            node.lineCount
        ]);

    if (!options.body) {
        data = data.concat(getExtensionFields(node, options));
    }

    data.node = node;
    return data;
}
1120705
function makePartSpan(value, doc) {
  var text = value;
  if (value.nodeType == 3) text = value.nodeValue;
  else value = doc.createTextNode(text);

  var span = doc.createElement("SPAN");
  span.isPart = true;
  span.appendChild(value);
  span.currentText = text;
  return span;
}
841845
def make_paragraphs(cls, root):
        """"""
        handler = cls()
        lxml.sax.saxify(root, handler)
        return handler.paragraphs
1349036
function parse(text) {
    const textLineByLine = text.split(LINEBREAKE_MARK);
    // it should be alternately Str and Break
    let startIndex = 0;
    const lastLineIndex = textLineByLine.length - 1;
    const isLasEmptytLine = (line, index) => {
        return index === lastLineIndex && line === "";
    };
    const isEmptyLine = (line, index) => {
        return index !== lastLineIndex && line === "";
    };
    const children = textLineByLine.reduce(function(result, currentLine, index) {
        const lineNumber = index + 1;
        if (isLasEmptytLine(currentLine, index)) {
            return result;
        }
        // \n
        if (isEmptyLine(currentLine, index)) {
            const emptyBreakNode = createBRNode(lineNumber, startIndex);
            startIndex += emptyBreakNode.raw.length;
            result.push(emptyBreakNode);
            return result;
        }

        // (Paragraph > Str) -> Br?
        const strNode = parseLine(currentLine, lineNumber, startIndex);
        const paragraph = createParagraph([strNode]);
        startIndex += paragraph.raw.length;
        result.push(paragraph);
        if (index !== lastLineIndex) {
            const breakNode = createEndedBRNode(paragraph);
            startIndex += breakNode.raw.length;
            result.push(breakNode);
        }
        return result;
    }, []);
    return {
        type: Syntax.Document,
        raw: text,
        range: [0, text.length],
        loc: {
            start: {
                line: 1,
                column: 0
            },
            end: {
                line: textLineByLine.length,
                column: textLineByLine[textLineByLine.length - 1].length
            }
        },
        children
    };
}
351805
def _node(handler, single=None, multi=None):
    """"""
    return _AbstractSyntaxTreeNode(handler=handler,
                                   single=(single if single else []),
                                   multi=(multi if multi else []))
570895
def _htmlify_text(self, s):
    """"""
    colored = self._handle_ansi_color_codes(html.escape(s))
    return linkify(self._buildroot, colored, self._linkify_memo).replace('\n', '</br>')
40199
def content_from_string(repo, text)
      mode, type, id, name = text.split(/ |\t/, 4)
      case type
        when "tree"
          Tree.create(repo, :id => id, :mode => mode, :name => name)
        when "blob"
          Blob.create(repo, :id => id, :mode => mode, :name => name)
        when "link"
          Blob.create(repo, :id => id, :mode => mode, :name => name)
        when "commit"
          Submodule.create(repo, :id => id, :mode => mode, :name => name)
        else
          raise Grit::InvalidObjectType, type
      end
    end