Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- 7 Aout 2017 - 22h-23h - @FGRibreau 

 This is a simple Proof Of Concept.
 Based on the ideas from http://bit.ly/2vzsf0n
 
 #TODO:
 - Display syntax error (rapid feedback loop)
 - Support more operators
-->
<div class="root">
  <div>
    <textarea id="text">
  Le 35e Montreux Jazz Festival s'est terminé [[affiche durée depuis: 16.07.2017]]. Son bilan est excellent.
  
  [[affiche si date < 02-07-2017]]Le Montreux Jazz festival commencera le 2 juillet 2017. Juste avant cette édition, nous avons interviewé son directeur.[[fin]][[affiche si date > 02.07.2017]]Le directeur du Montreux Jazz Festival s'est livré au Temps quelques jours avant la 51e édition de la manifestation[[fin]] - Mathieu Jaton, le festival vit une année charnière.
</textarea>
  </div>
  <div>
    <span></span>
  </div>
</div>
              
            
!

CSS

              
                * {
  padding: 0;
  margin: 0;
  font-family: monospace;
  font-size: 1rem;
  width: 100%;
  height: 100vh;
}
.root {
  display: flex;
  flex-direction: row;
}
.root > div {
}
textarea {
}

span {
}

              
            
!

JS

              
                /**
 This is a simple Proof Of Concept.
 Based on the ideas from http://bit.ly/2vzsf0n
 
 #TODO:
 - Display syntax error (rapid feedback loop)
 - Support more operators
**/
const subscribeToTextChange = (f) => {
  const el = document.getElementById("text");
  el.addEventListener('keyup', function(e){f(e.target.value)}, false);
  f(el.value);
}

const META_LANGUAGE = /\[{2}([^\]])+\]{2}/g;

const operators = [
  {
    is: exp => /affiche dur[é|e]e depuis/i.test(exp),
    run: (text, tokens) => {
      const { index, expression, rawExp } = tokens.shift();
      const [date] = /([0-9].*)$/g.exec(expression);
      return text.replace(
        rawExp,
        moment(date, "DDMMYYYY").locale("fr").fromNow()
      );
    }
  },
  {
    is: exp => /affiche si date/i.test(exp),
    run: (text, tokens) => {
      const { expression, rawExp } = tokens.shift();
      const date = expression.replace(/affiche si date\s+[\<\>]/i, "").trim();
      if (
        moment()[expression.includes("<") ? "isBefore" : "isAfter"](
          moment(date)
        )
      ) {
        // true => only remove first and second expression
        return text.replace(rawExp, "").replace(tokens.shift().rawExp, "");
      }

      // false => remove section
      const { rawExp: rawExp2 } = tokens.shift();
      return (
        text.substring(0, text.indexOf(rawExp)) +
        text.substring(text.indexOf(rawExp2) + rawExp2.length)
      );
    }
  }
];

function parse(text) {
  let match,
    tokens = [];
  META_LANGUAGE.index = 0;
  while ((match = META_LANGUAGE.exec(text))) {
    tokens.push({
      index: match.index,
      rawExp: match[0],
      expression: match[0].replace(/^\[\[/g, "").replace(/\]\]$/g, "")
    });
  }
  return { text: text, tokens: tokens };
}

function exec({ text, tokens }) {
  do {
    const op = operators.find(op => op.is(tokens[0].expression));
    if (!op) {
      throw new Error(`Unsupported operation "${tokens[0].expression}"`);
    }
    text = op ? op.run(text, tokens) : text;
  } while (tokens.length > 0);

  return text;
}

const displayResult = text => (document.querySelector("span").innerText = text);

const flow = (...fs) => v => fs.reduce((m, f) => f(m), v);
const tap = f => v => {
  f(v);
  return v;
};
const debug = v => console.debug(JSON.stringify(v, null, 2));

const run = flow(parse, tap(debug), exec, displayResult);

subscribeToTextChange(run);

              
            
!
999px

Console