javascript - 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.
解决方案
我不确定,但我首先想到的是尝试为此使用 Python。我会使用BeautifulSoup来查找列表项,并使用 Python 来进行一些字符串操作。
推荐阅读
- spring-boot - 使用 JPA 的 Spring Boot Batch 动态多数据源
- netlogo - Netlogo:乌龟明显的古怪行为
- ios - SwiftUI - 如果 TabView 嵌套在 NavigationLink 中,TabView 内的视图会在一秒钟后跳转
- python - 如何概括导入脚本
- nlp - 为什么运行“python run_squad.py”不起作用?
- java - 将 yaml 配置映射到 java hashmap
- excel - Power Query 根据索引添加月份列
- reactjs - 带有反应构建的空白页面
- objective-c - 为什么我看不到 NStextView 的内容
- javascript - Click 事件在 D3 US Map 上不起作用,并且 mouseover 事件仅在特定状态下起作用