📜 ⬆️ ⬇️

Selection of source syntax for habratopikov

Good day.

First of all, I would like to thank w999d for an invite :) In response, I wanted to do something nice for the habračan :)

When I wrote my first post on Habre in the sandbox, I noticed that Habr, for some mysterious reason for me, does not support the syntax highlighting tag for posts. When you write any article on programming, the source code must be formatted, otherwise it will not be read by anyone. Then I somehow managed with some third-party formatter, whose work for the PHP code did not suit me much. But the thought to make a normal formatter for habrachen is in my head. However, even if it turns out that I invented the bicycle, the time I spent dealing with the formatter source was definitely not wasted.
')

So, imagine the most alpha version of the formatter HabraSyntax: http://habrasyntax.fractalizer.ru

After formatting, it turns out something like this:

<?php
/* ======================================================================*\
|| #################################################################### ||
|| # vBulletin 3.7.3
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2008 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # www.vbulletin.com | www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================
*/

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting ( E_ALL & ~ E_NOTICE ) ;

// #################### DEFINE IMPORTANT CONSTANTS #######################
define ( ' THIS_SCRIPT ' , ' ajax ' ) ;
define ( ' CSRF_PROTECTION ' , true ) ;
define ( ' LOCATION_BYPASS ' , 1 ) ;
define ( ' NOPMPOPUP ' , 1 ) ;

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$ phrasegroups = array ( ' posting ' ) ;
switch ( $ _POST [ ' do ' ] )
{
case ' fetchuserfield ' :
case ' saveuserfield ' :
$ phrasegroups [ ] = ' cprofilefield ' ;
$ phrasegroups [ ] = ' user ' ;
}

// get special data templates from the datastore
$ specialtemplates = array ( ' bbcodecache ' ) ;

// pre-cache templates used by all actions
$ globaltemplates = array ( ) ;

// pre-cache templates used by specific actions
$ actiontemplates = array (
' fetchuserfield ' = > array (
' memberinfo_customfield_edit ' ,
' userfield_checkbox_option ' ,
' userfield_optional_input ' ,
' userfield_radio ' ,
' userfield_radio_option ' ,
' userfield_select ' ,
' userfield_select_option ' ,
' userfield_select_multiple ' ,
' userfield_textarea ' ,
' userfield_textbox ' ,
)
) ;

$ _POST [ ' ajax ' ] = 1 ;

// ######################### REQUIRE BACK-END ############################
require_once ( ' ./global.php ' ) ;
require_once ( DIR . ' /includes/class_xml.php ' ) ;

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

( $ hook = vBulletinHook :: fetch_hook ( ' ajax_start ' ) ) ? eval ( $ hook ) : false ;

// #############################################################################
// user name search

if ( $ _POST [ ' do ' ] = = ' usersearch ' )
{
$ vbulletin -> input -> clean_array_gpc ( ' p ' , array ( ' fragment ' = > TYPE_STR ) ) ;

$ vbulletin -> GPC [ ' fragment ' ] = convert_ urlencode d_unicode ( $ vbulletin -> GPC [ ' fragment ' ] ) ;

if ( $ vbulletin -> GPC [ ' fragment ' ] ! = ' ' AND strlen ( $ vbulletin -> GPC [ ' fragment ' ] ) > = 3 )
{
$ fragment = htmlspecialchars_uni ( $ vbulletin -> GPC [ ' fragment ' ] ) ;
}
else
{
$ fragment = ' ' ;
}

$ xml = new vB_AJAX_XML_Builder ( $ vbulletin , ' text/xml ' ) ;
$ xml -> add_group ( ' users ' ) ;

if ( $ fragment ! = ' ' )
{
$ users = $ db -> query_read_slave ( "
SELECT userid, username FROM
" . TABLE_PREFIX . " user
WHERE username LIKE('
" . $ db -> escape_string_like ( $ fragment ) . " %')
ORDER BY username
LIMIT 15
" ) ;
while ( $ user = $ db -> fetch_array ( $ users ) )
{
$ xml -> add_tag ( ' user ' , $ user [ ' username ' ] , array ( ' userid ' = > $ user [ ' userid ' ] ) ) ;
}
}

$ xml -> close_group ( ) ;
$ xml -> print_xml ( ) ;
}
FractalizeR's HabraSyntax Source Code Highlighter .


Because the code is only written, comments and comments are welcome.

A sufficient number of programming languages ​​is supported, so ... :) Enjoy your work.

Source: https://habr.com/ru/post/75505/


All Articles