Repository navigation
[16.0][ADD] document_page_markdown: add new module - #654
Open
CristianoMafraJunior wants to merge 1 commit into
Open
CristianoMafraJunior wants to merge 1 commit into
CristianoMafraJunior wants to merge 1 commit into
Conversation
| import markdown | ||
|
|
||
| from odoo import api, models | ||
|
|
Contributor
There was a problem hiding this comment.
Suggested change
| from odoo.tools import html_sanitize | |
| """Render a Markdown source into the HTML inserted in a page.""" | ||
| if not source: | ||
| return "" | ||
| return markdown.markdown(source, extensions=self._markdown_extensions()) |
Contributor
There was a problem hiding this comment.
Suggested change
| return markdown.markdown(source, extensions=self._markdown_extensions()) | |
| html = markdown.markdown(source, extensions=self._markdown_extensions()) | |
| return html_sanitize(html) |
Python's markdown library allows raw HTML by default. Without html_sanitize(), someone pasting <script> or will execute arbitrary JavaScript in the preview dialog and in the page (Stored XSS).
|
|
||
|
|
||
| @tagged("post_install", "-at_install") | ||
| @tagged("post_install", "-at_install") |
Contributor
There was a problem hiding this comment.
Suggested change
| @tagged("post_install", "-at_install") |
duplicate code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Markdown in the Knowledge Base
Document Page Markdown (
document_page_markdown) lets you write knowledgebase content in Markdown, the same way you write a pull request description on
GitHub: you type Markdown, check the formatted result in the Preview tab, and
insert it in the page.
How to use it
1. Open the structure menu
Go to Knowledge > Pages, open or create a page, and type
/in the pagecontent. Pick Markdown from the menu — it sits in the Structure section,
next to Bulleted list, Table, Separator, Code and the others.
2. Write the Markdown
The Markdown box opens with two tabs, Write and Preview. You write in the
Write tab, either typing the syntax yourself or using the toolbar above the
field.
Each toolbar button applies its syntax to the selection, or to the line the
cursor is on:
#) and subheading (##)S**), italic (*), strikethrough (~~)</>>)-), numbered (1.) and checklist (- [ ])[text](url))---)3. Check the Preview tab
The Preview tab shows the formatted text, exactly as it will look in the page.
It is rendered server side by the very same function that produces the inserted
content, so what you see in the preview is what gets inserted.
4. Insert it in the page
Click INSERT. The formatted content is added at the cursor position, as
regular editor content. DISCARD closes the box without inserting anything.
From there, fill in the revision Name and Summary and save the page as usual.
What you can write
On top of the basics (headings, lists, bold, italic, links, quotes), these
extensions are enabled:
| A | B |with a| --- | --- |row.trailing spaces.
!!! note,!!! warning) for callouts.Need another extension? You can add it without touching this module: inherit
document.pageand extend the_markdown_extensions()method.Good to know
What gets stored in the page is the rendered content, not the original
Markdown source. When you reopen the page, you edit it with the usual rich text
editor — Markdown is the way in, not the storage format.
In practice:
working exactly as before.
/→ Markdown again and insert the newversion in place of the old one.
Quick reference
/in the page content → Markdowncc @etobella @rvalyi @marcelsavegnago @BhaveshHeliconia