【问题标题】:Creating an html list rendering from indented text tree从缩进的文本树创建 html 列表呈现
【发布时间】:2021-01-23 08:09:07
【问题描述】:

我正在尝试创建一个带有缩进文本的 html 页面。 例如: 文本文件:

1. hello
    - stack
    - overflow
        - how
    - are you

结果如下:

<ol>
<il>hello</li>
<ul>
<li>stack</li> ...

因此它将呈现为缩进列表。 我认为最好创建一个受a similar problem in Python 的答案启发的节点树

这是我从 Go 中的链接克隆的结构,它不能按预期工作,由于某种原因它卡在递归中:

func (n *node) addChildren(nodes []node) {
    childLevel := nodes[0].textStart
    for len(nodes) > 0 {
        // pop
        tempNode := nodes[0]
        nodes = nodes[1:]
        if tempNode.textStart == childLevel {
            n.children = append(n.children, tempNode)
        } else if tempNode.textStart > childLevel {
            nodes = append([]node{tempNode}, nodes...)
            n.children[len(n.children)-1].addChildren(nodes)
        } else if tempNode.textStart <= n.textStart {
            nodes = append([]node{tempNode}, nodes...)
            return
        }

    }
}

【问题讨论】:

    标签: html go text stack indentation


    【解决方案1】:

    我找到了Markdown

    作为任务的最佳工具!

    【讨论】:

      猜你喜欢
      • 2017-07-03
      • 2016-12-04
      • 1970-01-01
      • 2011-04-08
      • 2013-07-25
      • 1970-01-01
      • 2012-04-16
      • 2011-03-01
      • 2012-03-10
      相关资源
      最近更新 更多