Remove line numbers from SyntaxHighlighter - line-numbers

Is there any way to remove the line numbers of SyntaxHighlighter?
Thanks!

You can set the SyntaxHighliter's gutter configuration to false. This will remove the line number from your code.
<pre class="brush: java; gutter: false;"></pre>

Hit the "view plain" link?
Taking a look at the SyntaxHighlighter demo you will see it has buttons in the top right corner which you can click to either copy the code to your clipboard, see the actual source code (removing markup) and or print it.
Are you asking us how to remove the actual feature that adds the line numbers while still keeping the rest of the functionality in place? Are you asking us to do this for you?
In response to comment:
If you want to keep the functionality in place, and just remove the line numbers you will need to download a copy of the javascript file for yourself and remove the features you don't want. the SyntaxHighlighter download page allows you to download your very own version of the highlighter, it also tells you that is is licensed under the LGPL 3, which means you have to follow those rules when you make and use your modifications.
If you want, you may come back and ask individual Javascript questions, if you get stuck in a particular spot, but we are not TopCoder nor will we re-write code for you.

If you don't want to edit your existing markup, you can turn it off globally by editing the shCore.js file:
var sh = {
defaults : {
...
...
...
/** Enables or disables gutter. */
'gutter' : false,
...
...
...
},
...
...
...
}

You can set the default of 'gutter' => 0 in SyntaxHighlighter Evolved version 3.2.1 by editing the file syntaxhighlighter.php. Look for this in the file:
// Create array of default settings (you can use the filter to modify these)
$this->defaultsettings = (array) apply_filters(
'syntaxhighlighter_defaultsettings', array(
'theme' => 'default',
'loadallbrushes' => 0,
'shversion' => 3,
'title' => '',
'autolinks' => 1,
'classname' => '',
'collapse' => 0,
'firstline' => 1,
'gutter' => 0,
'htmlscript' => 0,
'light' => 0,
'padlinenumbers' => 'false',
'smarttabs' => 1,
'tabsize' => 4,
'toolbar' => 0,
'wraplines' => 1, // 2.x only
) );

Related

Drupal9: Saving form as node in SQL (custom module example)

i develop a custom module with forms to save data in SQL-Datebase. I want to use for that the node-structure.
Normal SQL-savings for example table works but not for the node-tables.
Any idea what is going wrong?
This ist my Code for saving, which works in non-node-tables:
public function submitForm(array &$form, FormStateInterface $form_state) { $connection = \Drupal::service('database');
$result = $connection->insert('node.node__body')
->fields(['body_value'])
->values([
'body_value' => 'text for body',
])
->execute();
$form_state->setRedirect('modulname.form');
}
Use Entity API in Drupal to manipulate or create a node.
In your case,
$node = \Drupal::entityTypeManager()->getStorage('node')->create(
[
'type' => 'page',
'title' => 'New Basic Page',
'body' => 'text for body'
]
);
Here, type is the content type machine name. Don't forget to update with your own. Also you probably want to inject the entity_type.manager service and use in the code.
Get more info here: Working with entities in Drupal

How to keep blank lines around array in PhpStorm

I use PhpStorm 2019.1.
I need to set up code style with new lines around arrays. Keep it always.
$smt = $value;
$ss = [
'pr' => '4_',
'r5d' => '4_n',
'm4q' => '6_n',
'p3e' => '3_n',
'ctu' => '4_pn',
'orv' => '4on',
'eem' => '4on'
];
$smth = [];
I was seeking of these settings in Settings > Editor > Code style > PHP > Blank lines. Apparently It has to be there. But I didn`t find it. There were only settings to insert new lines around functions and classes but not around arrays.
Where is the settings which would help me with it? Or is this feature deprecated in this editor version?

Yii 2 nav widget visible vs accessible

I have a yii\bootstrap\Nav, where I have several menu items. One of them is the logout. Consider these two examples.
$menuItems = [
[
'label' => 'Logout ('. Yii::$app->user->identity->username. ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post'],
'visible' => !Yii::$app->user->isGuest,
],
]
vs
if (!Yii::$app->user->isGuest) {
$menuItems[] =
[
'label' => 'Logout ('. Yii::$app->user->identity->username. ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post'],
];
}
My Application crashes with the error for the
Trying to get property of non-object
on the line with Yii::$app->user->identity->username.
I use the second solution which works fine, but can you explain why the code executes bypassing the 'visible' parameter for the first block.
In the second case you check for not a guest and this mean that
Yii::$app->user
is a correct objecy and then you can access to username
in first you use only the visible menuitem attribute this as described in doc mean
http://www.yiiframework.com/doc-2.0/yii-widgets-menu.html#$items-detail
Visible: boolean, optional, whether this menu item is visible.
Defaults to true.
this mean that this attribute manage the hide or show of the menu item. But in this case the code for user remain the same so based on fact that a guest don't crate a proper user object you have the rror for accessi a propert ofr a null object
In your first code block
Yii::$app->user->identity->username
change it to
(Yii::$app->user)?("Logout(".(Yii::$app->user->identity->username.")"):'Login'
NOTE: change url accordingly. visibility is not required to configure.
If there is no login user Yii::$app->user->identity->username statement cannot return username because there is no user identity exist (Yii::$app->user->identity is null)

Accessing content of textarea in Drupal-7-Theme-Form

in my custom theme-settings.php (zen-subtheme) i put following code to get a new textarea with textformat in my theme-settings:
<?php
function paper_form_system_theme_settings_alter(&$form, &$form_state) {
$form['paper_data'] = array(
'#type' => 'text_format',
'#title' => 'Put Text in here:',
'#rows' => 5,
'#resizable' => FALSE,
'#default_value' => 'xyz..',
'#format' => 'full_html'
);
}
the form is working perfektly, but when i want to access the variable by writing
<?php
$pdata = theme_get_setting('paper_data');
echo $pdata;
?>
in my page.tpl.php, the content of the variable is not rendered - instead the word "Array" is printed ...
What's wrong and why? (If i use 'textarea' as type instead of 'text_format', all is rendered well.)
You will understand when you use something like the Devel module's dpm() function to check the variable rather than echo(). Coding Drupal without the Devel module is, IMHO, folly.
The issue very likely stems from your use of the text_format type. As you can see, it saves both the textarea value as well as an associated text format. When this is used Drupal returns the data in structured form which varies depending on the type of format.
dpm() is your friend :)

How load extra plugins for Zend Dojo Form Element Editor?

I have simple Zend_Dojo_Form with Editor element, when I add aditional plugins I got notice from firebug
Cannot find plugin linkdialog
the code
class Some_Form extends Zend_Dojo_Form
{
public function init() {
$this->addElement('Editor', 'content', array(
'label'=> 'Some editor title',
'dijitParams' => array(
'extraPlugins'=>array('linkdialog')
),
);
}
}
How I can enable aditional plugins for Zend_Dojo_Form_Element_Editor? I tried to include manualy, but same results.
dojo.require("dijit._editor.plugins.LinkDialog");
any suggestions?
Thanks #Alan Kay, you got me on the right track, but to elaborate a little more.
There seems to be two categories of Dojo editor plugins, '(built-in) plugins' and 'extraPlugins'.
Here's a list of built-in plugins (unsure if it's up-to-date). You can add built-in plugins on Dojo enabled Zend Forms Elements fine:
$this->addElement('editor', 'summary', array(
'label' => 'Summary:',
'plugins' => array(
// NOTE: specifying any will lose the default builtin plugins,
// so need to re-add the ones you want.
// Builtin plugins
'bold', 'italic', 'underline', '|',
'insertOrderedList', 'insertUnorderedList', '|',
'indent', 'outdent', '|',
'justifyLeft', 'justifyRight', 'justifyCenter', 'justifyFull', '|',
// dijit._editor.plugins that work
'foreColor', 'hiliteColor', '|', // TextColor
'fontName', 'fontSize', 'formatBlock', '|', // FontChoice
'createLink', 'insertImage', '|', // LinkDialog
'viewSource', // ViewSource
)
));
Alternatively, there are two main libraries of extraPlugins, Dijit (http://dojotoolkit.org/reference-guide/dijit/_editor/plugins.html#dijit-editor-plugins) and Dojox (http://dojotoolkit.org/reference-guide/dojox/editor/plugins.html#dojox-editor-plugins). Unfortunately, 'extraPlugins' are unavailable in Zend Framework until the next minor release (1.12) ZF-11511. You could use the patch to create your own library to extend Zend_Dojo_Form_Element_Editor in the meantime.
Note, when specifying 'extraPlugins', you want to use the 'short name' (e.g. 'createLink'), not the 'resource' (e.g. 'linkdialog'):
"The bolded text represents the resource; the basic text represents the
"short name" to be added to the extraPlugins list." 'Using Plugins' (http://dojotoolkit.org/documentation/tutorials/1.6/editor/)
However, note in the above example, it's possible to include the 'short names' for some Dijit extraPlugin 'resources', but not Dojox to my knowledge. Unsure why this is (haven't looked into dojo src - anyone?). Try your luck.
I don't know if this will work for your exact syntax, but you don't want to set 'LinkDialog', you want 'createLink'. I'm guessing 'extraPlugins'=>array('createLink') is the change you need
I know the following works for me:
$this->addElement(new Zend_Dojo_Form_Element_Editor('content',
array(
'label' => 'Content:',
'class' => 'soria',
)
)
);
$this->contents->addPlugins(array('|', 'createLink');