I'm using RDiscount to convert Markdown to html in my application. Actually when I add some code in my markdown it generates code and pre tags but I want to add a class to the code tag how can I do this ? I need to parse generated HTML with Nokogiri or something like this ?
Rdiscount does not seem able to do this on its own. Parsing the result (with Nokogiri or whatever) might do the trick, but could be expensive. If you can, switch to another lib, like Redcarpet for example. This one lookes like it can be extended quite easily to fit your needs
One thing is sure, you can't tell Rdiscount to do it, it has no option for it. I looked at Rdiscount source code and this is what I end up in the file generate.c:
static void
printcode(Line *t, MMIOT *f)
{
int blanks;
Qstring("<pre><code>", f);
for ( blanks = 0; t ; t = t->next ) {
if ( S(t->text) > t->dle ) {
while ( blanks ) {
Qchar('\n', f);
--blanks;
}
code(f, T(t->text), S(t->text));
Qchar('\n', f);
}
else blanks++;
}
Qstring("</code></pre>", f);
}
No option to add any class to code and pre.
If you need to add a class to format the markup, maybe you can try a workaround and generate a div with a class before the
<div class="myclass">
<pre><code>
Is it feasible for you?
Related
in ckeditor5 by cdn to include ckeditor.js
I would like to change entermode that instead of ?
is it possible?
Thanks
If you wnat to use <BR> as change line code in CKeditor 5, then just use "Shift+Enter" can make it happen.
Here is the code if you still want to make <P> display likes <BR> one's:
p {
margin: 0;
}
Seriously, I got same problem like your's......then I found Shift+Enter.
You could handle the enter event and make it trigger shiftEnter instead.
editor.editing.view.document.on(
'enter',
( evt, data ) => {
editor.execute('shiftEnter');
//Cancel existing event
data.preventDefault();
evt.stop();
}, {priority: 'high' });
source: https://github.com/ckeditor/ckeditor5/issues/1141#issuecomment-403403526
What I did in PHP is the following:
$replaceClosingTag = str_replace('</p>', '<br>', $_POST['message']);
$emailMessageText = str_replace('<p>', '', $replaceClosingTag);
I replaced the closing tag with a <br> and the opening tag with an empty space.
It is dirty but it worked for me. Probally with javascript you can do something similar.
And for the editor margin style I used this:
.ck.ck-editor__editable_inline p {
margin-bottom: 0;
}
Because I use a CDN and this overrides that class.
The question is 2 years old but hopefully this helps for someone in the future.
For anyone using Vue looking to achieve this, adding Ramast's solution as a plugin to editorConfig worked for me (following the instructions here: https://github.com/ckeditor/ckeditor5-vue/issues/58)
On the WebStorm for example and I believe in any Intellij product.
You can easily refeactor the code and style it as you like from the setting 'Code Style'.
But, the styling and refactoring actually change the binaries of the file.
for example if you decide you want new line after { it will add \n in each place.
I want to know if it possible to only visually display those different to the coder.
If I'm coding like this:
var func = function()
{
// Blah
}
And another programmer on the team code like this:
var func = function() {
// Blah
}
and also if I code like this:
var text = "";
and the other like this:
var text = '';
The thing is that I don't really care how it would actually be like in the saved file. I only care how it would be displayed to the programmer.
It is possible to achieve this ?
Simple answer: No. That's because coding rules exist and besides things like changed binaries you have the problem of version control as well. which style of your code should be versioned? While VCS' are able to deal with different line endings, what you ask for isn't supported anywhere.
I've created an API module in prestaShop and I am generating an XML output to a certain CMS page. Thing is that I can't disable the layout.
I just need to render the XML output from the module (and no html).
Any ideas please? (I am not using the webservice classes)
At least.. Is it possible to do this from a module?
Thanks,
Dan
Override the method "display" of your controller and output whatever you want.
If you do not want to display layout, do not call parent::display().
I have a problem like you. And I knew how to disable it.
You just need add two lines below to your module:
$this->display_header = false;
$this->display_footer = false;
Example:
public function initContent(){
parent::initContent();
$this->display_header = false;
$this->display_footer = false;
$this->setTemplate('display.tpl');
}
How to write '{' in inline event handler in the mxml tag itself?
Suppose I want to write this and dont want to make a function for this two line statement...
click="{if { (_absences!='')chkAbsences.selected = true; chkRegularHrs.selected = false;} else {chkAbsences.selected=false};}"
Thanks guys...
you have to escape that character. the same happens with the &.
When compiling MXML, first it has to be a valid XML file. So, there are certain characters for which you need to accommodate and write ugly stuff like if ( X && Y ) ...
How to escape..
PS: Do what #bedwyr says and use a script block for lengthy functions. you'll thank him/her later.
It's really simple:
<s:Button>
<s:click>
<![CDATA[
function clickHandler(event:MouseEvent):void
{
trace("CLICK!");
}
]]>
</s:click>
</s:Button>
I have a view that displays several nodes. I want to place node form below each displayed node. Both node_add and drupal_get_form directly in template.php works fine, but I get forms with same form ID of NODETYPE_node_form and validation and submitting does not work as expected.
If you had to put several node forms on one page, what would be your general approach?
Progress so far...
in template.php while preprocessing node
$author_profile and $content is set before.
$unique = $vars['node']->nid;
$node = new StdClass();
$node->uid = $vars['user']->uid;
$node->name = $vars['user']->name;
$node->type = 'review';
$node->language = '';
$node->title = t('Review of ') . $vars['node']->realname . t(' by ') . $vars['user']->realname . t(' on ') . $content->title;
$node->field_review_to_A[0]['nid'] = $nodeA->nid;
$node->field_review_to_B[0]['nid'] = $vars['node']->nid;
$node->field_review_to_profile[0]['nid'] = $author_profile->nid;
if(!function_exists("node_object_prepare")) {
include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
}
//$vars['A_review_form'] = drupal_get_form('review_node_form', $node);
$vars['A_review_form'] = mymodule_view($node, $unique);
in mymodule module
function mymodule_view($node, $unique) {
if(!function_exists("node_object_prepare")) {
include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
}
$output = drupal_get_form('review_node_form_' . $unique, $node);
return $output;
}
function mymodule_forms($form_id, $args) {
$forms = array();
if (strpos($form_id, "review_node_form_") === 0) {
$forms[$form_id] = array('callback' => 'node_form');
}
return $forms;
}
function mymodule_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && $form_id != $form['type']['#value'] .'_node_form' && $form['type']['#value'] == 'review') {
$type = content_types($form['#node']->type);
if (!empty($type['fields'])) {
module_load_include('inc', 'content', 'includes/content.node_form');
$form = array_merge($form, content_form($form, $form_state));
}
$form['#pre_render'][] = 'content_alter_extra_weights';
$form['#content_extra_fields'] = $type['extra'];
//$form['#id'] = $form_id;
//$form['#validate'][0] = $form_id . '_validate';
$form['title']['#type'] = 'value';
$form['field_review_to_A']['#type'] = 'value';
$form['field_review_to_B']['#type'] = 'value';
$form['field_review_to_profile']['#type'] = 'value';
}
}
Questions
My take on summarizing unclear questions...
Is this good general approach for displaying multiple node forms on same page?
Is it OK to copy/paste code from content modules content_form_alter function in function mymodule_form_alter? Will it not brake things if content module is updated?
Should i set $form['#id']? Without it all forms has same HTML form ID of node_form, with it ID is unique, like review_node_form_254. Thing is that there is no difference of how form is submitted. Setting $form['#validate'][0] does not seem to influence things too. Maybe I should set $form[button]['#submit'][0] to something else? Now its node_form_submit.
Why validation does not work even with unique form id and form validate function? If i submit last form without required field all previous forms gets particular fields red. should I make my own validation function? what level - form or field? Any tips on where to start?
You need to implement hook_forms() to map different ids to the same builder function.
The NODETYPE_node_form ids you mention are already an example of this mechanism, as they are all mapped to the same builder function (node_form()) within the node modules node_forms() implementation.
You can find links to more examples in the 'Parameters' explanation off the drupal_get_form() function.
This was exceptionally useful to me.
Documentation on all the drupal APIs is so lacking - I was tearing my hair out. The crucial bit for me, that I don't think is covered anywhere else on the net:
CCK adds its fields to your form through hook_form_alter() . But it does this based on the form_id. So if the form ID is different (cause you want multiple ones on the same page), you need to replicate a bit of the CCK code to add the fields to your form regardless.
That is what this does brilliantly.
I really did not dig to the bottom of it, but it seems to me that you pretty much did all the relevant digging by yourself.
From what I understand by inspecting the code only, you are right in thinking that content_form_alter() is the show-stopper.
Maybe this is a naïve suggestion, but what about writing your own implementation of hook_form_alter() starting from the content_form_alter() code but changing the conditions that make the alteration to occur? I am thinking to something along these lines:
function modulename_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) &&
stripos($form_id, $form['type']['#value'] .'_node_form')) {
...
}
}
I did not actually test the code above, but I hope it is self-explenatory: you actually trigger the changes for a give customised type of content if MYCCKTYPE_node_form is a substring of the actual form_id (es: MYCCKTYPE_node_form_234).
Hope this helps at least a bit... Good luck! :)
EDIT: TWO MORE THINGS
It just occurred to me that since your custom implementation of hook_form_alter() will live aside the CCK one, you would like to add a check to avoid the form to be modified twice something like:
&& $form_id != $form['type']['#value'] .'_node_form'
The other way you might try to implement this by not using CCK but implementing you custom type programmatically (this might even be an advantage if you plan to use your module on various different sites).