This plugin allows you to have placeholders in your site, that can be dynamically replaced at runtime using JavaScript (see demo page).
This README is just a short intro to the package.
For a quick start and detailed information please see the documentation for the last release.
The documentation is also available in the docs folder of the source code and can be built locally with MkDocs.
If you want to use the latest development version (may be broken/buggy from time to time), you can install it by:
- 
Cloning the repository:
git clone https://github.com/six-two/mkdocs-placeholder-plugin cd mkdocs-placeholder-plugin - 
Building/Downloading the JavaScript files. Choose any of the following ways:
- Build it with npm (natively), by running the 
./build-docs.shscript. - Build it in a (docker/podman) container by using the 
Dockerfilein thetypescriptdirectory. The whole thing can be done by running thebuils.shscript in the root directory:Once you see mkdocs running, you can terminate it with./build.sh
Ctrl-C. - Downloading the files from the development version of the documentation (hosted and built by Vercel):
curl https://dev.mkdocs-placeholder-plugin.six-two.dev/placeholder.min.js -o src/mkdocs_placeholder_plugin/assets/placeholder.min.js curl https://dev.mkdocs-placeholder-plugin.six-two.dev/placeholder.min.js.map -o src/mkdocs_placeholder_plugin/assets/placeholder.min.js.map
 
 - Build it with npm (natively), by running the 
 - 
Installing the package with pip:
python3 -m pip install . 
The corresponding documentation is hosted at https://dev.mkdocs-placeholder-plugin.six-two.dev.
- Added 
html_prefix_optionalsetting to enable silencing warnings when using placeholders in link URLs (see #12). 
- Fixes innerHTML replacement method breaking functionality such as the search box (see #9).
 
- Version 0.5.0 accidentally shipped with old JavaScript code. This causes the JavaScript to crash with the error 
Type mismatch: inline_editor_icons should be boolean, but is undefined. If you encounter this issue, make sure to update to the latest version withpip install -U mkdocs-placeholder-pluginor pin the fixed version withpip install mkdocs-placeholder-plugin==0.5.0-1. 
- Added inline editable placeholders (see #6) and enabled them by default:
- If you want to disable them by default, add 
inline_editors: falseto thesettingsattribute in yourplaceholder-plugin.yaml. - If you want to disable them and prevent users from enabling them, add 
normal_is_alias_for: dynamicto thesettingsattribute in yourplaceholder-plugin.yaml. - You can choose how inline placeholders look via the 
inline_editor_stylesetting. 
 - If you want to disable them by default, add 
 - You can now embed the placeholder settings editor anywhere in your page with 
<div class="placeholder-settings-panel"></div>. 
- Validators can copy rules from other validators via the 
import_rules_fromattribute - New validators: 
email,linux_interface,mac_address,uuid 
- Configuration format changed:
- Validators are no longer defined in-line and instead defined in a 
validatorssection -> easier to reuse custom validators. - Placeholders now need to be specified in a 
placeholderssection. - Most settings are now in the configuration file instead of in your 
mkdocs.yml. 
 - Validators are no longer defined in-line and instead defined in a 
 - Some actions can now be toggled by visitors of the site. The settings open when you click the gear icon on a (dynamic) placeholder input table.
 - (By default) values are saved when the focus leaves a text field.
 - Removed static placeholder input tables (
<placeholdertable>). - Uncoupled the code from MkDocs. You should now be able to relatively easy port the project to other Markdown based static site generators if you want to.
 
- Removed 
Apply all changesbuttons. See issue #3 
This release may be a bit buggy due to the rewrite and the documentation is not entirely accurate yet. I will update the docs after I also clean up / rewrite the python code (planed for v0.4.0).
- Rewrote the JavaScript code in TypeScript:
- Packed and minified using Webpack, so the file is a bit smaller
 - Should find stupid errors I make in code paths that I do not test (often)
 - Sophisticated update logic: Instead of always reloading the page it tries to update the DOM in-place (if possible), which should improve user experience a bit and is much faster
 - Nested placeholders (placeholders that contain placeholders that contain placeholder...) no longer need to be specified in a speific order in the configuration file.
 - A placeholder's 
default-functionand a validator rule'smatch_functionare now evaluated usingnew Function(...)instead ofeval(...), so you need to add a return statement. 
 
- When an JavaScript generated 
auto-input-tableis empty, now a info box is shown (instead of nothing / an empty table). - Bugfixes:
auto_placeholder_tables_javascripthad no effect.- Pressing 
Enteron text fields without validators did not try to reload the page, 
 
- Added input validation:
- Predefined types: 
domain,file_name_linux,file_name_windows,hostname,ipv4_address,ipv4_range_cidr,ipv4_range_dashes,ipv6_address,path_linux,path_windows,port_number,url_any,url_http - Custom validators with rules that either use 
regexormatch_function 
 - Predefined types: 
 - Added 
placeholder_extra_jsfield to plugin configuration (for loading custom functions) - Added 
default-functionattribute for placeholders 
- Split JavaScript code into multiple files and made it available via the global 
PlaceholderDataandPlaceholderPluginobjects. These interfaces are not stable, so you should probably not try to rely on them to much. - Added 
replace_everywhereattribute for placeholders - Changes to textbox values are only stored, when you press 
Enter - Dynamically generated tables now honor 
add_apply_table_column - Improved JavaScript debugging: timestamps, more messages, and you can disable the page reload
 - Some visual fixes, mainly for the 
Material for MkDocstheme 
- Improved placeholder input tables:
- Can now specify which columns to use (and their order)
 - Only show apply values column, if at least one column contains input elements
 
 - Properly handle checkboxes and dropdown menus when performing static replacements
 - Hide JavaScript console output by default
 - Generate automatic placeholder table dynamically, since if checkboxes / dropdowns are used, it can not be predicted, which values are used on the page.
 - Added 
description-or-namecolumn type to placeholder tables. 
- Add option to reload the page if a checkbox/dropdown is changed or a text field is changed and 
Enteris pressed (to immediately show the new values). This is enabled by default. - Set initial value for placeholder input fields to "Please enable JavaScript"
 - Added option to automatically insert placeholder input tables at the top of each page
 
- Added new input types (checkbox & dropdown menu)
 - Also allow numbers in placeholder names (everywhere except the first character)
 - Moved to typed mkdocs config (now requires mkdocs 1.4+)
 - Disable input elements for read only placeholders
 - Moved a lot of code around, significantly changed JavaScript file
 
- Placeholder config: Placeholders can now have attributes (like 
description) - Tables with inputs for all placeholders on a page can now be generated via 
<placeholdertable>elements - Stack traces for fatal exceptions can now be seen with the 
-vflag (mkdocs serve -v) - When performing static replacements, the contents are now HTML escaped
 - Added script 
mkdocs-placeholder-replace-static.py 
- Implemented static replacements for user-selected pages
 - Added timing options. This should make it possible to use with MermaidJS diagrams, but may not always work
 
- Show a warning if an 
inputelement references a non-existent variable - Show a warning if a variable name does not match the recommended format
 - Perform type checks/conversions when loading placeholder data from the data file
 
This is just for me :)
- 
Run linters:
mypy src
pyflakes src
Check npm code with podman:
podman run -it --rm --workdir /typescript -v "$(pwd)/typescript:/typescript" localhost/placeholder-npm:latest npm run lintOr with docker:
docker run -it --rm --workdir /typescript -v "$(pwd)/typescript:/typescript" placeholder-npm:latest npm run lint - 
Update the changelog in this README file.
 - 
Update version number in
./pyproject.tomlandtypescript/src/api.ts. - 
Run
./build.shto compile the latest JavaScript code and test that it works.poetry buildwill only build the latest Python code, and incompatibilities between Python and JS code can break the release. - 
Disable
debug_javascriptinplaceholder-plugin.yaml. - 
Build and update package:
poetry build poetry publish
 - 
Create a commit for the release (
release: Version 0.X.Y) and push it. - 
Add a tag named
0.X.Y:git tag 0.X.Y
 - 
Update the
latest-releasebranch, so that the documentation website gets updated:git push git branch --force latest-release HEAD git push --tags origin latest-release
 
If you don't have them, install pip-tools:
python3 -m pip install pip-toolsThen update requirements.txt:
pip-compile -UThese are only used for the build process, so keeping them up to date is not that critical.
Start a container with nodeJS:
podman run -it --rm -v "$(pwd)/typescript:/mnt" node:latest bashIn the container run the following commands to update the typescript/package*.json files on the host:
cd /mnt
npm i -g npm-check-updates
ncu -u
npm i --package-lock-onlyThen rebuild the docker image on the host:
cd typescript/
podman build --tag placeholder-npm .