docute icon indicating copy to clipboard operation
docute copied to clipboard

embed code fragments from external sources

Open jthegedus opened this issue 5 years ago • 8 comments

Issuehunt badges

I would like to import fenced code from GitHub repo files similar to https://docsify.js.org/#/embed-files?id=embedded-code-fragments

Is this on the roadmap?


IssueHunt Summary

Sponsors (Total: $100.00)

Become a sponsor now!

Or submit a pull request to get the deposits!

Tips

jthegedus avatar Mar 21 '19 21:03 jthegedus

Yeah but probably using a different syntax, like:

<!-- embed foo.js as code block -->
#embed(/foo.js code language="js")

<!-- result: -->
```js
// content in foo.js
```

A fragment:

#embed(/foo.md fragment)

<!-- result: -->

something to embed

Where foo.md looks like:

# title

<!-- docute-embed-start -->

something to embed

<!-- docute-embed-end -->

egoist avatar Mar 22 '19 09:03 egoist

Sounds great! A couple more things :stuck_out_tongue: is it possible to add support for:

  • these files to be externally loaded?
  • adding arbitrary fencing?

For instance:

<!-- embed example.js as code block -->
#embed(
  https://raw.githubusercontent.com/someuser/somerepo/code/example.js
  type=code
  language="js"
  fence="some-demo"
)

<!-- .../example.js -->
...
/// [some-demo-start]
...
/// [some-demo-end]
...

<!-- result -->
// some content from example.js within the /// [some-demo]

and then

<!-- import content from other .md file -->
#embed(
  https://raw.githubusercontent.com/someuser/somerepo/example.md
  type=fragment
  fence="some-fragment"
)

<!-- .../exmaple.md -->
...
<!-- some-fragment-start -->
something to embed
<!-- some-fragment-end -->
...

Being able to define the fence allows multiple partials from a single file to be imported.

Externally loading code decouples the need for it to live alongside the documentation, say in an examples repo.

jthegedus avatar Mar 22 '19 21:03 jthegedus

The api.processMarkdown(fn) API now can return a Promise:

屏幕快照 2019-03-23 下午6 30 29

You can probably implement it as a plugin using this API:

const embedPlugin = () => {
  return {
    name: 'embed',
    extend(api) {
      api.processMarkdown(async markdown => {
        return modifiedMarkdown
      })
    }
  }
}

new Docute({
  plugins: [embedPlugin()]
})

egoist avatar Mar 23 '19 10:03 egoist

Sweet, I'll give this a go soon! Cheers!

jthegedus avatar Mar 23 '19 11:03 jthegedus

@issuehunt has funded $100.00 to this issue.


IssueHuntBot avatar Jun 09 '19 03:06 IssueHuntBot

Can i take this?

janat08 avatar Jun 13 '19 07:06 janat08

@janat08 Feel free. I got caught up with life!

jthegedus avatar Jun 13 '19 10:06 jthegedus

@egoist please merge, its been half a year

janat08 avatar Jan 29 '20 09:01 janat08