lkwdwrd / code-snippets

A code/text snippet plugin for WordPress.
0 stars 0 forks source link

Ace, CodeMirror, or something else? #1

Open tddewey opened 10 years ago

tddewey commented 10 years ago

Ace is supported by Mozilla and Cloud9 IDE. http://ace.c9.io/

CodeMirror is folded into webkit's editor. https://www.webkit.org/blog/2518/state-of-web-inspector/#source-code

There may be less crazy editors, but these are two of the big players.

lkwdwrd commented 10 years ago

After looking into both of them for a bit I'm landing on CodeMirror because of the runmode method. It appears to have a standalone version. If it works, we can use CodeMirror to do both the editing on the back end and the display on the front end. I'll want to do some testing to make sure it's not too heavy, but from the looks of things, it should work fine. Thoughts?

tddewey commented 10 years ago

Using the runmode method would certainly cut down on the complexity of things if we syntax highlighted on client-side. But, as you mentioned, I'd be concerned about loading an entire editor library when only the syntax highlighting is needed.

That said, I've been trying to think of a way to store/display the rendered HTML for each snippet while avoiding multiple db queries.

What's your thought about storing rendered HTML in post meta for each shortcode/snippet added? Something similar to how oembeds are cached? Would cut down on front-end code needed and would eliminate any possibility of FLOUT

lkwdwrd commented 10 years ago

So figure I'll post it here to record my thoughts:

If we create a hidden taxonomy along with our custom post type and create a new taxonomy term upon creation of our post, we can then cache the output in the term description field. Doing it that way will allow us to attach the post or page to the taxonomy and run a get_the_terms() to grab all of the cached output. Multiple posts can be assigned to each term and if the term gets updated, the posts still have access to the updated data within the term description field.

As a fallback if something happens and a snippet shortcode gets place into a post without the term, or the term description gets corrupted somehow, etc. we can run to the post type itself and grabbed a secondary cached item out of the post_content_filtered column.

Not the best description of it, but at least puts the idea down in text.