首页 > 解决方案 > How to make an HTML list copyable as markdown

问题描述

I would like it so that when a user selects the text of a list <ul> on a page, it copies it as markdown list with - im a list item hyphenated lines. Likewise, I would like for definition lists <dl> to be copied as - term: definition, while they might be styled like this:

ul {
  list-style-type: none;
  display: flex;
}

li {
  padding: 10px;
}
<ul>
  <li>a</li>
  <li>b</li>
  <li>c</li>
  <li>d</li>
</ul>
<dl>
  <dt>foo</dt>
  <dd>bar</dd>
  <dt>hello</dt>
  <dd>world</dd>
</dl>

Wondering what needs to be done to get it to copy/paste as this:

- a
- b
- c
- d

- foo: bar
- hello: world

Without writing a whole bunch of JavaScript.

标签: javascripthtmlcss

解决方案


我不确定,但我首先想到的是尝试为此使用 Python。我会使用BeautifulSoup来查找列表项,并使用 Python 来进行一些字符串操作。


推荐阅读