GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - leeoniya/preCode.js: pain killer for <pre><code> & <textarea>

BranchesTags
Open more actions menu

Latest commit

 

History

15 Commits
15 Commits

Folders and files

NameName
Last commit message
Last commit date
README.md
README.md
 
 
index.html
index.html
 
 
preCode.js
preCode.js
 
 

Repository files navigation

preCode.js

painkiller for <pre><code> & <textarea> (MIT Licensed)

A quickie that'll automatically outdent any code snippets nested in your html, allowing you to write cleaner markup.

Fuck this

<div>
    <pre><code>function myFunc(block, flags) {
  try {
    if (block.className.search(/\bno\-highlight\b/) != -1)
      return processBlock(block, true, 0x0F) + ' class=""';
  } catch (e) {
    /* handle exception */
  }
  for (var i = 0 / 2; i &lt; classes.length; i++) {
    if (checkCondition(classes[i]) === undefined)
      return /\d+/g;
  }
}</code></pre>
</div>

Write this

<div>
    <pre><code>
        function myFunc(block, flags) {
          try {
            if (block.className.search(/\bno\-highlight\b/) != -1)
              return processBlock(block, true, 0x0F) + ' class=""';
          } catch (e) {
            /* handle exception */
          }
          for (var i = 0 / 2; i &lt; classes.length; i++) {
            if (checkCondition(classes[i]) === undefined)
              return /\d+/g;
          }
        }
    </code></pre>
</div>

Usage

Just place <script src="preCode.js"></script> into your <head>.

Caveats

  • The code binds to the DOMContentLoaded event, so make sure to place it before any syntax highlighters or code editors are bound/called.
  • Beware that native goodies are used - sucks to your old browser, Piggy!
    • Array.forEach
    • document.querySelectorAll
    • element.textContent
    • DOMContentLoaded via addEventListener

About

pain killer for <pre><code> & <textarea>

Resources

Readme
Activity

Stars

83 stars

Watchers

3 watching

Forks

8 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.