bevacqua / woofmark

:dog2: Barking up the DOM tree. A modular, progressive, and beautiful Markdown and HTML editor
https://bevacqua.github.io/woofmark
MIT License
1.63k stars 65 forks source link

How can I add command button then render it? #10

Closed danvim closed 9 years ago

danvim commented 9 years ago

I have the following code:

woofmark(document.querySelector('#ta'), {
        parseMarkdown: megamark,
        parseHTML: domador,
        render: {
            commands: function (button, id) {
                button.className = 'btn';
                var n = {
                    "bold": 'B',
                    "italic": 'I',
                    "quote": 'Q',
                    "code": 'C',
                    "ol": 'OL',
                    "ul": 'UL',
                    "heading": 'H',
                    "link": 'A',
                    "image": 'IMG'
                };
                button.innerHTML = n[id];
            },
            modes: function (button, id) {
                button.className = 'btn';
                var n = {
                    "markdown": "MarkDown",
                    "html": "HTML",
                    "wysiwyg": "WYSIWYG"
                }
                button.innerHTML = n[id];
            }
        }
    }).addCommandButton("Jump", function jump() {});

Is there is not a built-in way to render added command buttons? Or do I have to do it outside woofmark?

tobigit commented 7 years ago

@danvim How do you solved the Problem? I would like to disallow the features "link" and "image". It would be nice when the regarding buttons won't be rendered. And on top i would like to implement the features "underline" and "line trough".

jywarren commented 7 years ago

Hi, add commands with: https://github.com/bevacqua/woofmark#editoraddcommandbuttonid-combo-fn

For hiding features, that's probably a separate issue -- but I did so using JavaScript after initializing woofmark, which is not so clean but definitely works: https://github.com/publiclab/PublicLab.Editor/blob/master/src/adapters/PublicLab.Woofmark.js#L278-L281

danvim commented 7 years ago

@tobigit I forgot since it was long ago, but it was through looking through the source code. I eventually went for another editor.

tobigit commented 7 years ago

@jywarren @danvim Ok, thank you. If woofmark will take part of our software i will need an configurable and clean way to handle command-buttons.

@bevacqua, is there something in your pipeline regarding configurable command-buttons?

jywarren commented 7 years ago

I think there's a possibility of adding a new options param for rendered buttons, but it'd a bit complex to implement. Currently, buttons are referred to:

I guess to create this feature, you'd have to provide an opportunity to add new items to the strings, and new commands that correspond to them, before render occurs.