Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add marked configuration #232

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/config/config.yaml
/config/mathjax.js
/config/marked.js
/content/*
/src/vendor/
Thumbs.db
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ See more at https://hub.docker.com/r/xy2z/pinedocs/
1. Setup the web server to the `PineDocs/public` dir (use `php -S localhost:89 -t public` for testing)
1. (Optional) Rename the file `config/config-example.yaml` to `config/config.yaml` for changing settings (see below)
1. (Optional) Rename the file `config/mathjax-example.js` to `config/mathjax.js` for changing settings of Mathjax (see below)
1. (Optional) Rename the file `config/marked-example.js` to `config/marked.js` for changing settings of Marked (see below)
1. (Optional) Change the file `config/custom.js` when using Docker to customize Javascript
1. (Optional) Change the file `config/custom.css` when using Docker to customize CSS

Expand All @@ -105,8 +106,9 @@ See more at https://hub.docker.com/r/xy2z/pinedocs/

Feel free to edit the `config/config.yaml` file to fit your needs.

You can [configure Mathjax](https://docs.mathjax.org/en/latest/options/index.html#configuring-mathjax-1) by editing the `config/mathjax.js` file.

You can :
- [configure Mathjax](https://docs.mathjax.org/en/latest/options/index.html#configuring-mathjax-1) by editing the `config/mathjax.js` file
- [configure Marked](https://marked.js.org/using_advanced#options) by editing the `config/marked.js` file

#### Settings

Expand Down
3 changes: 3 additions & 0 deletions config/marked-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
marked.setOptions({

});
6 changes: 6 additions & 0 deletions docker/usr/bin/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ if [ ! -f /data/pinedocs/config/mathjax.js ]; then
echo 'Created mathjax.js config file.'
fi

# Marked config
if [ ! -f /data/pinedocs/config/marked.js ]; then
mkdir -p /data/pinedocs/config
cp /app/pinedocs/config/marked-example.js /data/pinedocs/config/marked.js
echo 'Created marked.js config file.'

# Custom.css config
if [ ! -f /data/pinedocs/config/custom.css ]; then
mkdir -p /data/pinedocs/config
Expand Down
1 change: 1 addition & 0 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
// 'hide_folders_in_navigation' => PineDOcs::$config->hide_folders_in_navigation,
'enable_mathjax' => PineDocs::$config->enable_mathjax,
'mathjax_configuration' => PineDocs::$config->mathjax_configuration,
'marked_configuration' => PineDocs::$config->marked_configuration,
),
'errors' => PineDocs::$errors,
);
Expand Down
5 changes: 4 additions & 1 deletion public/js/PineDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ $(function() {
// File size is too large to render.
self.render_download_link(data);
} else if (data.extension == 'md' || data.extension == 'markdown') {
// Markdown
// Markdown configuration
eval(config.marked_configuration);

// Render Markdown
self.elements.file_content.html(marked(data.content))

// Syntax highlighting
Expand Down
24 changes: 24 additions & 0 deletions src/PineDocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ static public function load_config() {
} else {
self::$config->mathjax_configuration = '';
}

// Load Marked configuration
self::$config->marked_configuration = self::load_config_marked();
}


Expand Down Expand Up @@ -169,4 +172,25 @@ static private function load_config_mathjax() {
return $data_mathjax;
}

static private function load_config_marked() {
$config_marked_path = '../config/marked.js';

if (!file_exists($config_marked_path)) {
// Create marked.js by copying marked-example.js.
$create = copy('../config/marked-example.js', '../config/marked.js');
if (!$create) {
exit('Error: Could not automatically create config/marked.js. You need to manually copy config/marked-example.js to config/marked.js');
}
}

// Read data
$data_marked = file_get_contents($config_marked_path);

if (!$data_marked) {
exit('Error: Could not read config/marked.js.');
}

return $data_marked;
}

}