1

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.

Lance
  • 75,200
  • 93
  • 289
  • 503
  • 1
    You can manipulate the copied text with javascript: https://stackoverflow.com/questions/42089713/modify-clipboard-content-after-copy-event-javascript-jquery But there you can't really recognize the list anymore, so you will probably need to convert the selection (https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection) to markdown all by yourself. – Fii Jun 09 '19 at 11:53

1 Answers1

0

I'm not sure but the first thing that comes to my mind would be to try using Python for this. I would use BeautifulSoup to find the lists items and Python to do some string manipulation.

alextechtai
  • 101
  • 2