https://github.com/lazypanda10117/docsify-pdf-embed
A simple plugin for embedding PDF in Docsify.
https://github.com/lazypanda10117/docsify-pdf-embed
Last synced: 3 months ago
JSON representation
A simple plugin for embedding PDF in Docsify.
- Host: GitHub
- URL: https://github.com/lazypanda10117/docsify-pdf-embed
- Owner: lazypanda10117
- License: mit
- Created: 2018-11-04T22:30:50.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-02T01:14:39.000Z (about 2 years ago)
- Last Synced: 2024-12-12T13:48:24.928Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 273 KB
- Stars: 55
- Watchers: 2
- Forks: 10
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-docsify - docsify-pdf-embed - A docsify plugin for embedding PDF on any page [@lazypanda10117](https://github.com/lazypanda10117). (Plugins)
README
# Docsify PDF Embed Plugin
A simple plugin for embedding PDF in Docsify with the use of PDFObject.js
#### Simple Installation:
To use, simply put these 2 lines below where you import the `docsify.min.js` file.
```html
```
Then, whenever you want to embed a PDF, type the following in the `.md` file that you want to put in:
```markdown
### Here are some of your previous markdown contents
blah blah blah
```pdf
path-to-the-pdf-file
(``` to close the codeblock)
```

#### Remarks for users who have defined custom markdown parsing rules:
If you have custom parsing rules for code section of the markdown file (shown below), then you need to follow the next section.
```javascript
window.$docsify = {
name: 'some name',
repo: 'some git repository',
homepage: 'some_homepage.md',
notFoundPage: 'some_404_page.md',
markdown: {
//If you have defined the follow section,
//then you need to follow the steps in the next section.
//(only the code section matters in this plugin)
/* SECTION START
code: function(code, lang){
some custom functions here
return some_custom_results;
}
SECTION END */
}
}
```
#### Quick fix for the above problem:
Put the block of code inside the `code: function(code, lang){ //put it here }` (the part that is mentioned above). Then put your previously defined custom parsing rules for markdown code section in the section mentioned in the comment block below.
```javascript
var renderer_func = function(code, lang, base=null) {
var pdf_renderer = function(code, lang, verify) {
function unique_id_generator(){
function rand_gen(){
return Math.floor((Math.random()+1) * 65536).toString(16).substring(1);
}
return rand_gen() + rand_gen() + '-' + rand_gen() + '-' + rand_gen() + '-' + rand_gen() + '-' + rand_gen() + rand_gen() + rand_gen();
}
if(lang && !lang.localeCompare('pdf', 'en', {sensitivity: 'base'})){
if(verify){
return true;
}else{
var divId = "markdown_code_pdf_container_" + unique_id_generator().toString();
var container_list = new Array();
if(localStorage.getItem('pdf_container_list')){
container_list = JSON.parse(localStorage.getItem('pdf_container_list'));
}
container_list.push({"pdf_location": code, "div_id": divId});
localStorage.setItem('pdf_container_list', JSON.stringify(container_list));
return (
'
'
);
}
}
return false;
}
if(pdf_renderer(code, lang, true)){
return pdf_renderer(code, lang, false);
}
/* SECTION START: Put other custom code rendering functions here
i.e. If the language of the code block is LaTex,
put the code below to replace original code block with the text:
'Using LaTex is much better than handwriting!' inside a div container.
if (lang == "latex") {
return ('
Using LaTex is much better than handwriting!');
}
SECTION END */
return (base ? base : this.origin.code.apply(this, arguments));
}
```
Congrats! Now you have PDF embedding functionality for your use cases of Docsify.
__Acknowledgement__:
> Thanks to [njleonzhang](https://github.com/njleonzhang/docsify-edit-on-github/)'s Docsify edit on GitHub plugin for being an inspiration