Skip to content

Commit

Permalink
Fix #12: Allow specifying the available heading levels
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Aug 26, 2024
1 parent 18ce743 commit bb3ac71
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Next version
- Updated the ProseMirror dependencies.
- Added extremely hacky german translations for the dialogs.
- Added Django 5.1 to the CI matrix.
- Allowed specifying the heading levels for the menu. The schema itself supports
all heading levels (1-6) as before.


0.7 (2024-08-02)
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ It's possible to slightly customize the field or widget by passing an optional
"history": True, # Enable undo and redo
"html": True, # Add a button which allows editing the raw HTML
"typographic": True, # Highlight typographic characters
"headingLevels": [1, 2, 3, 4, 5], # Available heading levels
}
If you only want to support paragraphs, strong, emphasis, sub- and superset and
Expand Down
2 changes: 1 addition & 1 deletion django_prose_editor/static/django_prose_editor/editor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function createEditor(textarea, config) {
history(),
menuPlugin(
[
blockTypeMenuItems(schema),
blockTypeMenuItems(schema, config.headingLevels),
listMenuItems(schema),
linkMenuItems(schema),
markMenuItems(schema),
Expand Down
10 changes: 4 additions & 6 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function materialButton(textContent, title) {
})
}

export function blockTypeMenuItems(schema) {
export function blockTypeMenuItems(schema, headingLevels) {
if (!schema.nodes.heading) return []

const heading = (level) => ({
Expand All @@ -58,12 +58,10 @@ export function blockTypeMenuItems(schema) {
},
})

const _levels = headingLevels || [1, 2, 3, 4, 5]

return [
heading(1),
heading(2),
heading(3),
heading(4),
heading(5),
..._levels.map(heading),
{
command: setBlockType(schema.nodes.paragraph),
dom: materialButton("notes", "paragraph"),
Expand Down

0 comments on commit bb3ac71

Please sign in to comment.