Skip to content
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
51 changes: 37 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,56 @@
pastefromhtml
=============

pastefromhtml is a Zim plugin that lets you paste lists, links, text, and now images (thanks to an anonymous commit) from html clipboard data.
pastefromhtml is a Zim plugin that lets you paste lists, links, text, images, and LaTeX/MathML equations from HTML clipboard data.

#### Installation
You can install pastefromhtml by creating a folder with files `htmlcdparser.py` and `__init__.py` in your zim/plugins directory.

You can install pastefromhtml plugin in Zim, by creating a folder with files `htmlcdparser.py` and `__init__.py` in your zim/plugins directory.

For installation in Linux, you can place a folder (with files `htmlcdparser.py` and `__init__.py` inside) in `~/.local/share/zim/plugins` directory.

pastefromhtml plugin can also be installed by cloning the github repository in zim/plugins directory:
For installation in Linux, place the folder in `~/.local/share/zim/plugins`.

You can also install by cloning the repository:
```sh
cd ~/.local/share/zim/plugins
git clone https://github.com/cetinkaya/pastefromhtml.git
```

To enable the plugin, click on the menu entry `Edit / Preferences`, then go to `Plugins` tab.
To enable the plugin, click on `Edit / Preferences`, then go to the `Plugins` tab.

#### Dependencies

#### Use
For basic use (text, links, images) no additional dependencies are needed.

For **LaTeX/KaTeX equation rendering** (e.g. when pasting from Claude.ai) the following must be installed:
- `latex` and `dvipng` (from TeX Live)

For **MathML equation rendering** (e.g. when pasting from GitHub Copilot) additionally:
- `python-pypandoc` and `pandoc`

On Arch/Manjaro:
```sh
sudo pacman -S texlive dvipng python-pypandoc
```

pastefromhtml adds menu entries (`Tools / Paste from HTML`, `Edit / Paste from HTML`) and a right-click context-menu entry, as well as a keyboard shortcut (`ctrl + shift + v`) in Zim.
On Debian/Ubuntu:
```sh
sudo apt install texlive dvipng pandoc python3-pypandoc
```

If the dependencies are not installed, equations are silently skipped and the rest of the content is pasted normally.

#### Use
pastefromhtml adds menu entries (`Tools / Paste from HTML`, `Edit / Paste from HTML`) and a right-click context-menu entry, as well as a keyboard shortcut (`ctrl + shift + v`) in Zim.

After you copy lists/links/text/images in your browser, paste them into Zim by clicking on the menu entry or by using the shortcut `ctrl + shift + v`.
After you copy content in your browser, paste it into Zim by clicking on the menu entry or by using the shortcut `ctrl + shift + v`.

Equations are automatically rendered to PNG and embedded as images in the page's attachments folder.

#### Quirks
#### Configuration
To access the configuration options, click on `Edit / Preferences`, navigate to the `Plugins` tab, select `Paste from HTML`, and click the `Configure` button.

##### Images inside anchor tags
Available options:

When pasting image tags `<img>` that are placed inside anchor tags `<a>`, the default behavior of pastefromhtml is to only paste the URL that the anchor tag refers to (unless it is the URL of the image). There is an option that can be configured so as to paste the images instead of URLs of the anchor tags. To access this option, you can click on Edit/Preferences in the menu bar, navigate to the Plugins tab, and select Paste from HTML. After that, click on the Configure button located on the right-hand side.
- **Images inside anchor tags** – when pasting `<img>` tags inside `<a>` tags, paste the image instead of the link URL
- **Reload page after pasting** – reload the page after pasting to apply formatting
- **LaTeX equation font size** – font size in pt for rendered equations (default: 14)
- **LaTeX equation image DPI** – resolution of rendered equation images (default: 200)
- **LaTeX dark mode** – use white font color for equations (for dark Zim themes)
19 changes: 17 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@
class PasteFromHTMLPlugin(PluginClass):
plugin_info = {
"name": _("Paste from HTML"),
"description": _("This plugin lets you paste HTML clipboard data."),
"description": _(
"This plugin lets you paste HTML clipboard data.\n\n"
"For LaTeX/KaTeX equation rendering the following must be installed:\n"
" - latex (texlive)\n"
" - dvipng\n"
" - python-pypandoc (for MathML from Copilot etc.)\n\n"
"On Arch/Manjaro: sudo pacman -S texlive dvipng python-pypandoc"
),
"author": "Ahmet Cetinkaya",
"help": "Plugins:Paste from HTML"
}
Expand All @@ -32,6 +39,9 @@ class PasteFromHTMLPlugin(PluginClass):
# key, type, label, default
('image_inside_a', 'bool', _('For image tags <img> inside anchor tags <a>, paste images instead of links'), False),
('reload_page', 'bool', _('Reload page after pasting'), False),
('latex_font_size', 'int', _('LaTeX equation font size (pt)'), 14, (6, 24)),
('latex_dpi', 'choice', _('LaTeX equation image DPI'), '200', ('96', '120', '150', '200', '300', '400', '600')),
('latex_dark_mode', 'bool', _('LaTeX equations: use white font (for dark themes)'), False),
)


Expand Down Expand Up @@ -95,7 +105,12 @@ def pastefh(self):
if target in ["text/html", "TEXT/HTML", "HTML Format"]:
data = get_fragment(data)
cursor = self.window.pageview.get_cursor_pos()
h = HTMLCDParser(self.preferences['image_inside_a'])
h = HTMLCDParser(
self.preferences['image_inside_a'],
latex_font_size=self.preferences['latex_font_size'],
latex_dpi=int(self.preferences['latex_dpi']),
latex_dark_mode=self.preferences['latex_dark_mode'],
)
buffer.insert_at_cursor(h.to_zim(data, folder))
self.window.pageview.set_page(self.window.pageview.page)
self.window.pageview.set_cursor_pos(cursor)
Expand Down
Loading