I am using drupal serving as a blog system. Now I need to show sample code in the articles. How can I let the editor recognize the programming language and highlight the syntax?
1 Answer
Depending on the WYSIWYG editor you're using, you should have the option to add <pre> tags, which will preserve spacing so your code is formatted properly.
You can then style the <pre> tags in your CSS, or use something like this Google code prettifier, which will do syntax highlighting.
You may have to allow the <pre> tag in your tag whitelist in your Drupal admin, under Admin > Configuration > Text Formats (for Drupal 7) or Admin > Site Configuration > Input Formats (for Drupal 6).