Ich arbeite an einem benutzerdefinierten CMS, wo CKEditor (4.5.1) für freundliche HTML-Content-Generierung integriert ist.Block/Inline 'Meta-Markup' in CKEditor
Eine der Funktionen, die wir liefern, ist die Möglichkeit, Teile der Seite auf bestimmte Benutzergruppen zu beschränken, und die sauberste Möglichkeit, dies zu tun, war, ein neues Tag zu erstellen und dieses zum Nachverfolgen zu verwenden Inhalt, z <restrict data-usertype="1,2,3">restricted content for user types 1, 2, 3 here</restrict>
, die durch das Backend entfernt werden würde.
Das Problem, das ich habe, ist, dass mein benutzerdefiniertes Tag implizit sowohl Block- als auch Inline-Tags unterstützen muss, und ich bin mir nicht sicher, wie ich das richtig einrichten soll.
Ich habe eine Vielzahl von Kombinationen von Dingen ausprobiert, die entweder das Hinzufügen von Inhalten überhaupt verbieten, oder das Plug-In vollständig deaktivieren (weil es mit ACFs eigener Plausibilitätsprüfung in Konflikt gerät); Im Moment wird die Konfiguration, die ich habe, lassen Sie mich den <restrict>
Block hinzufügen, lassen Sie mich im Dialog (einschließlich durch Doppelklick) bearbeiten, aber lassen Sie mich keinen Inhalt irgendwelcher Art verschachteln und verursachen CKEditor zu werfen 'konnte nicht Lese Attribute von Null 'warnt beim Zurückschalten in den Quellmodus.
Meine aktuelle Konfiguration des Plugins wird wie folgt:
CKEDITOR.dtd.restrict = {
a: 1, abbr: 1, address: 1, area: 1, article: 1, aside: 1, audio: 1, b: 1, bdi: 1, bdo: 1, blockquote: 1,
br: 1, button: 1, canvas: 1, cite: 1, code: 1, command: 1, datalist: 1, del: 1, details: 1, dfn: 1, div: 1,
dl: 1, em: 1, embed: 1, fieldset: 1, figure: 1, footer: 1, form: 1, h1: 1, h2: 1, h3: 1, h4: 1, h5: 1, h6: 1,
header: 1, hgroup: 1, hr: 1, i: 1, iframe: 1, img: 1, input: 1, ins: 1, kbd: 1, keygen: 1, label: 1, map: 1,
mark: 1, meter: 1, noscript: 1, object: 1, ol: 1, output: 1, progress: 1, p: 1, pre: 1, q: 1, ruby: 1, s: 1,
samp: 1, script: 1, section: 1, select: 1, small: 1, span: 1, strong: 1, sub: 1, sup: 1, table: 1,
textarea: 1, time: 1, u: 1, ul: 1, 'var': 1, video: 1, wbr: 1, '#': 1
}; // Allow <restrict> as a valid tag.
CKEDITOR.dtd.$block.restrict = 1;
CKEDITOR.dtd.$inline.restrict = 1;
CKEDITOR.dtd.$blockLimit.restrict = 1; // Treat <restrict> as a block limiter tag
CKEDITOR.dtd.$removeEmpty.restrict = 1; // Remove <restrict /> tags if they are empty
CKEDITOR.dtd.$transparent.restrict = 1; // Treat the tag as transparent as far as content models go
CKEDITOR.dtd.body.restrict = 1; // Allow it in the body, div and p tags.
CKEDITOR.dtd.div.restrict = 1;
CKEDITOR.dtd.p.restrict = 1;
var allowedEls = ['restrict'];
for (var i in CKEDITOR.dtd.restrict) {
if (CKEDITOR.dtd.restrict.hasOwnProperty(i) && i != '#') {
allowedEls.push(i);
}
}
// Define the widget.
editor.widgets.add('restrict', {
button: 'Restricted Content',
dialog: 'restrictDialog',
template: '<restrict />',
editables: {},
allowedContent: allowedEls.join(' ') + '[*]{*}(*)', // All the above elements, with any attributes, styles or classes.
requiredContent: 'restrict[data-*]',
upcast: function (element) {
return element.name == 'restrict';
},
init: function() {
// Some stuff which iterates through the various
// properties I care about, grabs from data
// attributes and pushes to this.setData().
},
data: function() {
// Some stuff that just fetches vars from this.data,
// sets the relevant data attribute and also sets an
// attribute on the span created by CKEditor since
// styling and ::before content is used to show who
// the block is visible to - the result is much like
// the Show Blocks plugin. This stuff all works
// correctly and being omitted changes nothing.
}
});
Ich glaube, ich habe falsch editables
eingerichtet und wahrscheinlich die allgemeinen erlaubt Inhalt Material für diesen Tag, aber ich kann nicht sehen, wie ich Ich sollte ein solches Tag erstellen und ich kann mir nicht vorstellen, dass das Erstellen eines solchen Phantom-Tags, das außerhalb des Browsers geparst wird, ein neues Problem darstellen würde.
Vielen Dank im Voraus!