GithubHelp home page GithubHelp logo

eddyluten / mkdocs-live-edit-plugin Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 2.0 47 KB

An MkDocs plugin that allows editing pages directly from the browser.

License: MIT License

CSS 7.56% JavaScript 43.15% Python 49.29%
documentation live-editing mkdocs mkdocs-plugin wiki

mkdocs-live-edit-plugin's Introduction

mkdocs-live-edit-plugin

PyPI version License: MIT example workflow Downloads

mkdocs-live-edit-plugin is an MkDocs plugin that allows editing pages directly from the browser.

Things you can do with this plugin when running via mkdocs serve:

  • Editing a page's Markdown source from the page itself.
  • Renaming a page's filename
  • Deleting a page
  • Creating a brand new page

Some basic editor shortcuts available while editing:

  • Ctrl+B/Cmd+B toggles your selection to be Bold
  • Ctrl+I/Cmd+I toggles your selection to be Italic
  • Alt+S/Opt+S toggles your selection to be Strikethrough
  • Ctrl+S/Cmd+S to save your changes

If you like this plugin, you'll probably also like mkdocs-categories-plugin and mkdocs-alias-plugin.

Installation

Using Python 3.10 or greater, install the package using pip:

pip install mkdocs-live-edit-plugin

Then add the following entry to the plugins section of your mkdocs.yml file:

plugins:
  - live-edit

Usage

A video showing how to use v0.1.0

If, for any reason, you want to override the port that the Live Edit WebSocket is operating on, you can do so by setting the websockets_port option for the live-edit plugin like so:

plugins:
  - live-edit:
      websockets_port: 9999 # or any other port you want

TODO

How Does it Work?

The short answer: WebSockets handle client-server communication, while MkDocs handles reloading when files change.

The Longer Answer

Once installed, when running your local live-reload server, the plugin registers a separate WebSockets server that runs on a specified port. Once your wiki is built, a WebSockets client is installed in your browser, allowing for asynchronous communication between the two.

When you edit the contents of a file in the browser, they are sent to the server via WebSockets, where the plugin writes the contents to disk. Here, MkDocs picks up on the change and sends a reload signal back to the browser -- this is the same live-reload mechanism that picks up on changes you make via a text editor.

A similar mechanism is in place for other operations like renaming and deleting.

Changelog

0.2.0

New Feature: Creating pages. The plugin now exposes a button that allows you to create a brand new page from any other page.

0.1.5

Bug fix: fixes an issue where the WebSocket connection would host on localhost over IPv6. See #3 for context.

0.1.4

Bug fix: Improved WebSocket connectivity and error handling. Updated the documentation to match.

0.1.3

Bug fix: The WebSocket connection now honors the hostname as supplied by the browser in window.location.hostname.

0.1.2

Bug fix: include missing data files

0.1.1

Bug fix: include non-python files in the package

0.1.0

Initial release with editing, renaming, and deletion logic in place.

mkdocs-live-edit-plugin's People

Contributors

eddyluten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mkdocs-live-edit-plugin's Issues

OSError: [Errno 99] error while attempting to bind on address ('::1', 8484, 0, 0): cannot assign requested address

Python version(s): 3.10.13 / 3.11.7

mkdocs-live-edit-plugin = "^0.1.4"

...
INFO    -  Documentation built in 21.14 seconds
INFO    -  live-edit websocket server starting
INFO    -  live-edit websocket server thread started
Exception in thread Thread-5 (server_thread_main):
Traceback (most recent call last):
  File "/home/user/.pyenv/versions/3.10.13/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/home/user/.pyenv/versions/3.10.13/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File ".venv/lib/python3.10/site-packages/live/plugin.py", line 221, in server_thread_main
    asyncio.run(self.event_loop())
  File "/home/user/.pyenv/versions/3.10.13/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/home/user/.pyenv/versions/3.10.13/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File ".venv/lib/python3.10/site-packages/live/plugin.py", line 207, in event_loop
    async with serve(
  File ".venv/lib/python3.10/site-packages/websockets/legacy/server.py", line 1098, in __aenter__
    return await self
  File ".venv/lib/python3.10/site-packages/websockets/legacy/server.py", line 1116, in __await_impl__
    server = await self._create_server()
  File "/home/user/.pyenv/versions/3.10.13/lib/python3.10/asyncio/base_events.py", line 1519, in create_server
    raise OSError(err.errno, 'error while attempting '
OSError: [Errno 99] error while attempting to bind on address ('::1', 8484, 0, 0): cannot assign requested address
INFO    -  [09:28:22] Watching paths for changes: 'docs', 'mkdocs.yml'
INFO    -  [09:28:22] Serving on http://127.0.0.1:8000/

Fix:

/live/plugin.py

async with serve(
        self.websocket_receiver,
        "localhost",
        self.config['websockets_port']
    ):
    ...
async with serve(
        self.websocket_receiver,
        "127.0.0.1",
        self.config['websockets_port']
    ):
    ...

PR coming shortly ๐Ÿ˜ƒ

Edit failing while attempted to edit from other devices

image

  • As show on the image , the web socket is running on the local-host , from same device edit is functioning correctly but from the other devices it is giving the above provided issue .
  • Can you please have a look at it and also if there is anything i am missing then let me know

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.