Coder Social home page Coder Social logo

kcmr / code-sample Goto Github PK

View Code? Open in Web Editor NEW
22.0 3.0 8.0 3.94 MB

A wrapper element for highlight.js

Home Page: https://kcmr.github.io/code-sample/

License: MIT License

HTML 21.95% JavaScript 75.02% CSS 3.03%
polymer-element polymer2 code-highlight highlighter web-component

code-sample's People

Contributors

kcmr avatar lpellegr avatar sergicontre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

code-sample's Issues

Injecting dynamic values in code snippet

I have a code snippet displayed with this great code-sample element:

<my-element my-attribute="DEFAULT_VALUE"></my-element>

However, I would like to replace "DEFAULT_VALUE" by a value retrieved dynamically. For example, a value available in an existing Polymer property. I mean something like the following:

<my-element my-attribute="[[myAttributeDefaultValue]]"></my-element>

The purpose is to display a configuration example. Unfortunately, the Polymer expression is not evaluated. Is there a way to achieve that?

non-template value passed to Polymer's html function

When references to JS literals are included, it is not able to escape expressions of the type
${example}

Example:

 export class Example extends ExampleBase {
                static get template() {
                  return html'
                        <p>${super.template}</p>
                    ';
                }
            }

Error in web console:

Uncaught Error: non-template value passed to Polymer's html function: undefined
at htmlValue (html-tag.js:63)
at template.innerHTML.values.reduce (html-tag.js:106)
at Array.reduce ()
at html (html-tag.js:106)

Not working for CSharp code, for example

I tried to use a template like this:

<code-sample type="csharp">
    <template preserve-content>
        void f()
        {
            int sum = 0;
            for (int i = 0; i < 100; i++)
            {
                List<int> result = CallFunction(i);
            }
        }
    </template>
</code-sample>

but I (strangely) obtain a result the '<' symbol in the 'for' is replaced by the < and it creates a closing tag '', corresponding erroneously to the List definition, as if it was a tag.
Am I missing anything?
Thanks
Andrea

webcomponentsjs messing with template content

I have a Polymer 3 element with the content:

<code-sample>
  <template preserve-content>
    <script src="foo" async></script>
  </template>
</code-sample>

On chrome it works just fine, but on Firefox with webcomponentsjs it renders incorrectly.

Chrome:

<script src="foo" async></script>

Firefox:

<script src="foo" async class="style-scope index-page"></script>

Does not work inside template

This has the same problem as Polymers demo-snippet...
It doesn't work inside another template ( aka inside a custom element )

2019 update and fix issues

Issues

  • Fix import not working when using Webpack #15

Code

  • Use LitElement instead of Polymer
  • Use open-wc/testing instead of WCT

Development

  • Improve serve (use Parcel bundler)
  • Move style to a stylesheet file
  • Add eslint config

Release / CI

  • Improve CI release config
  • Include a bundled release

Ampersand, html encoding

I'm running into a little issue here:

This:

<code-sample>
  <template>
    function both(x, y) {
      if (x && y) {
        return 'Both';
      }
    
      if (x && !y) {
        return 'First';
      }
    
      if (!x && y) {
        return 'Second';
      }
    }
  </template>
</code-sample>

renders like this:

function both(x, y) {
  if (x &amp;&amp; y) {
    return 'Both';
  }
    
  if (x &amp;&amp; !y) {
    return 'First';
  }
    
  if (!x &amp;&amp; y) {
    return 'Second';
  }
}

Do you know how I can easily get ampersands to display properly?

Copy code snippet

I really like your component. The only missing point I see is a copy button for copying the code snippet in one click. Adding this feature would be really awesome.

Render html

So, the wysiwyg editor that I'm using to create code samples does not use \n line breaks to create new lines, it uses <p> tags. I do not want the <p> tags to show up with my code (I'm creating code samples for JavaScript). What would you suggest to get rid of the <p> tags and instead have line breaks? I would have thought that adding the render attribute to code-sample would render the html, but it doesn't seem to be working. Thanks for any insights

import in webpack not working

When I try to use it via webpack + Polymer 3 + typescript it throws the error:

index.ts:53 ReferenceError: hljs is not defined
    at Object../node_modules/@kuscamara/code-sample/vendor/highlight/highlight.pack.js (highlight.pack.js:formatted:1)
    at __webpack_require__ (bootstrap:767)
    at fn (bootstrap:130)
    at Module../node_modules/@kuscamara/code-sample/code-sample.js (highlight.pack.js:formatted:1)
    at __webpack_require__ (bootstrap:767)
    at fn (bootstrap:130)
    at Module../src/components/index-page/index.ts (indexPage.684e59f8986e2130e02b.chunk.js:76)
    at __webpack_require__ (bootstrap:767)
    at fn (bootstrap:130)

Code:

import '@kuscamara/code-sample/code-sample.js'

Full code https://github.com/d4l3k/feedlight/blob/cc770115d7b85cb3674d74c2610a9773d68b4be3/www/src/components/index-page/index.ts#L3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.