In CKEditor 4, allow both <i> and <em> tags - ckeditor

Using CKEditor 4 I've changed the I button so that it generates <i> tags instead of <em>:
coreStyles_italic = { element: "i", overrides: "em" };
This works.
However, I also wish to add a style so that it's possible to add <em> tags too:
config.stylesSet = [
{ name: "Emphasis", element: "em" },
];
This superficially works — the little status bar at the bottom of the form field shows "body p em" – if I view source, or save the form, the <em> tags have been replaced with <i> because of the coreStyles_italic override.
Is there any way to allow both <i> and <em> tags?
(I also want to allow both <b> and <strong> tags, but assume that any fix will work for that too.)

Related

Mailchimp API and mc:repeatable

I'm working with the MailChimp Transactional API but am having an issue populating an email template that uses a mc:repeatable section. I can't find any docs or examples on how to do this. Here is the endpoint im using https://mailchimp.com/developer/transactional/api/messages/send-using-message-template/
And here is my email template
<!DOCTYPE html>
<html lang="en">
<head>
<title>Your Order</title>
</head>
<body>
<div>Thanks for your order</div>
<div>Your receipt for your order from</div>
<div mc:edit="store_name">Store Name</div>
<div>Order Type</div>
<div mc:edit="order_type">Type</div>
<div>Products:</div>
<table>
<tr mc:repeatable="products">
<td mc:edit="quantity">Quantity</td>
<td mc:edit="product_name">Product Name</td>
<td mc:edit="price">Price</td>
</tr>
</table>
</body>
</html>
I'm able to populate all of the mc:edit areas using this as the template_content in the request body:
const content = [
{
name: 'store_name',
content: 'Any Store Name'
},
{
name: 'order_type',
content: 'Pickup Order'
},
{
name: 'subtotal',
content: '$80.00'
},
{
name: 'taxes',
content: '$2.22'
},
{
name: 'fees',
content: '$0.00'
},
{
name: 'total',
content: '$82.22'
}
]
I can even populate a SINGLE row in the repeatable section if I add objects for quantity, product_name and price but I need to be able to REPEAT this section and add multiple quantity > product name > price lines.
Any advice or help or docs would be great, thanks!
From the MailChimp template language reference, it doesn't appear that <tr> elements are supported by mc:repeatable. See the third (bolded) point and note that, while <table> is a block level element, <tr> is not.
mc:repeatable
mc:repeatable is used to provide a duplication action for a particular element within a template.
Syntax: mc:repeatable.
Use mc:repeatable on block-level elements (like <div> and <p>) with the exception of lists, or inline elements (like <img>, <a>, and <span>).
mc:repeatable elements can be nested within each other, but use care if you’re going to do this. We don’t encourage this use.
mc:repeatable can be used on the same element as mc:edit, but nesting mc:repeatable beneath mc:edit will render content that is editable but not repeatable.
If you want to apply styles to repeatable container elements or elements within repeatable containers, either use class or apply them in-line. Don’t use the id attribute.
If they do happen to work, you might need to use mc:variant and per-product names for the subfields. Something like this:
<table>
<tr mc:repeatable="products" mc:variant="product1">
<td mc:edit="product1_quantity">Quantity</td>
<td mc:edit="product1_product_name">Product Name</td>
<td mc:edit="product1_price">Price</td>
</tr>
<tr mc:repeatable="products" mc:variant="product2">
<td mc:edit="product2_quantity">Quantity</td>
<td mc:edit="product2_product_name">Product Name</td>
<td mc:edit="product2_price">Price</td>
</tr>
<tr mc:repeatable="products" mc:variant="product3">
<td mc:edit="product3_quantity">Quantity</td>
<td mc:edit="product3_product_name">Product Name</td>
<td mc:edit="product3_price">Price</td>
</tr>
</table>
const content = [
{
name: 'product1_quantity',
content: '5'
}, {
name: 'product1_name',
content: 'Some Product'
}, {
name: 'product1_price',
content: '$49.99'
},
{
name: 'product2_quantity',
content: '1'
}, {
name: 'product2_name',
content: 'Some Other Product'
}, {
name: 'product2_price',
content: '$1,200'
},
{
name: 'product3_quantity',
content: '13'
}, {
name: 'product3_name',
content: 'Some Third Product'
}, {
name: 'product3_price',
content: '$17.50'
}
];
If this looks like it isn't for building a list from dynamic data, that's because I don't think it is. It looks like it's a tool for easily getting styles into the Campaign Builder.
Inside the builder, there is a Product concept that includes the kind of information you appear to want to send in your email. The tutorial for the builder indicates that while a Product section is repeatable, you need to have a source of data connected to the builder and must choose the Products to include at design time.
Use Product content blocks to add items from your connected online store. Each block is designed to contain a product name, custom description, price, and call-to-action button. And if you turn on e-commerce tracking in your email settings, your report will show purchase revenue.
To use a Product block, follow these steps.
Click a Product block or add one to your email. If you’re working with an existing block, skip to step 4.
In the Select a store modal, choose the store you want to add products from. If you haven’t yet connected a store, you’ll be prompted to do so.
Click the product you want to add.
In the Products menu, edit the Title, Button, and Link to URL as needed. You can also click the edit icon to choose a different product, or click the settings icon to check your store connection.

Set <span> tags under <li> tag in TYPO3

I am inserting <span> tags under <li> like this.
lib.parseFunc.tags {
li = TEXT
li {
current = 1
wrap = <li><span>|</span></li>
}
}
Since <li> tags are defined as TEXT cObject, the <a> tags set from Ckeditor under <li> are also treated as TEXT cObject and the links are displaying like t3://page?uid=18 which are not accessible.
Does anyone know how can I parse <a> tags as links but doesn't affect the <li> configuration? Thanks

CKEditor4 mentions output template not outputting entire templated string in wysiwyg editor and being inserted as new <p> tag instead of inline

I'm having a few issues implementing the Mentions plugin in CKEditor4:
The outputTemplate isn't acting as expected. The <span class="tag is-delete"></span> from the template is completely omitted when inserted into the editor after selecting from the mentions dropdown.
The outputTemplate is inserted in a separate <p> tag all by itself, whereas I want the tags to be inline.
Example of current output:
<p>After looking into this issue, I can confirm</p>
<p><a data-value="1" class="tags has-addons"><span class="tag is-info">John Doe</span></a></p>
<p>'s bug report is reproducible in all major production releases; therefore, further escalation is required.</p>
Example of expected/desired output:
<p>After looking into this issue, I can confirm <a data-value="1" class="tags has-addons"><span class="tag is-info">John Doe</span><span class="tag is-delete"></span></a>'s bug report is reproducible in all major production releases; therefore, further escalation is required.</p>
My relevant code
My exact CKEditor configuration can be viewed here.
I'm using the Div Editing Area plugin in place of the iframe, so that my global css (Bulma) is utilized for the tags inside the wysiwyg editor.
<div class="field">
<p class="control" id="discussion-inputs">
<textarea id="discussion-textarea" class="textarea" placeholder="Add a comment..." style="margin-top: 0px; margin-bottom: 0px; height: 128px;"></textarea>
</p>
</div>
CKEDITOR.replace( document.querySelector( '#discussion-textarea' ), {
allowedContent: true,
mentions: [
{
marker: '#',
minChars: 3,
feed: "{{ url_for('api.user_list') }}",
itemTemplate: '<li data-id="{id}" class="dropdown-item">{name}</li>',
outputTemplate: '<a data-value="{id}" class="tags has-addons"><span class="tag is-info">{name}</span><span class="tag is-delete"></span></a>'
}
]
});
Small sample of the output received from the api.user_list endpoint
[
{
"email": "johnd#email.com",
"id": 1,
"name": "John Doe"
},
{
"email": "janed#email.com",
"id": 2,
"name": "Jane Doe"
}
]
My questions
How can I make the entire outputTemplate actually output without being truncated or stripped of any of the supplied html tags/classes?
How can I make sure the tags are inserted inline instead of as separate, new <p> tags, so there are no unneccessary linebreaks added to the typed message?
Bonus: How can I make it so the mention tag, after it's properly inserted into the editor area, when clicked will be removed instead of the cursor being placed at the spot of the text that was clicked? The idea is to prevent the user from being able to modify the #'d username to one that is not valid.

Xpath for any html element containing specific text inside html tag

Need to find xpath that matches any html tag that contains the word sidebar in any html tag. Example:
<p class='my class'>This is some text</p>
<h1 class='btn sidebar btn-now'><p>We have more text here</p><p> and anoter text here</p></div>
<div id='something here'>New text here</div>
<div id='something sidebar here'>New text again</div>
<nav class='this sidebar btn'>This is my nav</nav>
<sidebar><div>This is some text</div></sidebar>
I need xpath to get any html element that has word 'sidebar' between starting < and ending > html tag, be it class, id or html tag name. In the above example I need to get as result:
<h1 class='btn sidebar btn-now'><p>We have more text here</p><p> and anoter text here</p></div>
<div id='something sidebar here'>New text again</div>
<nav class='this sidebar btn'>This is my nav</nav>
<sidebar><div>This is some text</div></sidebar>
Needs to be xpath not regex
Try below and let me know if it's not what you're searching for:
//*[contains(#*, "sidebar") or contains(name(), "sidebar")]
contains(#*, "sidebar") means node with any attribute that contains "sidebar"
contains(name(), "sidebar") - node name that contains "sidebar"
If you need only id or class to contain "sidebar":
//*[contains(#id, "sidebar") or contains(#class, "sidebar") or contains(name(), "sidebar")]

How do I get the text within HTML tags?

I want to get the text within a certain HTML tag. It looks like:
<div id="data123">data1: value1<br>data2: value2<br> data3: value</div>
My code looks like:
html_page = Nokogiri::HTML open 'my_url'
who_is_raw = html_page.css('div#data123')[0] #.text
I get either the text within the <div> tag without <br> tags or the whole <div> with all <br> inside. But, I want only the text within that <div> tag and <br> tags inside it.
How do I do that?
Try with inner_html
who_is_raw = html_page.css('div#data123')[0].inner_html

Resources