Coder Social home page Coder Social logo

dimpu / ngx-md Goto Github PK

View Code? Open in Web Editor NEW
264.0 8.0 80.0 33.95 MB

Angular(ngx) directive for parsing markdown content in your web application.

Home Page: https://dimpu.github.io/ngx-md/

TypeScript 49.56% JavaScript 5.63% HTML 10.22% CSS 30.32% C++ 0.39% Java 1.14% SCSS 2.75%
ng ng2 markdown angular-module marked prismjs

ngx-md's Introduction

Angular Markdown (NgxMd)

Build Status Build Status npm version npm npm npm FOSSA Status

Supports Angular2,4,5,6,7,12

Source @ https://github.com/dimpu/ngx-md

Table of contents

  1. Getting Started
  2. Installation instructions
  3. Usage & Demo
  4. Contributing
  5. License

Getting Started

ngx-md contains NgxMdModule for Angular.

Additionally we use marked.js and prismjs for this component.

Installation instructions

Install ngx-md from npm:

npm install ngx-md --save

or using yarn:

yarn add ngx-md

How to use it with:

Usage & Demo

Main source of API documentation and usage scenarios is available at https://dimpu.github.io/ngx-md/.

Contribution

Is very welcome! And remember, contribution is not only PRs and code, but any help with docs or helping other developers to solve issues are very appreciated! Thanks in advance!

Quick Guide

app.module.ts

This library has dependency on HttpClientModule. It should be always provided in your application.

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { NgxMdModule } from 'ngx-md';
import { HttpClientModule } from '@angular/common'
import { AppComponent } from '../src/app.component';

@NgModule({
  imports: [
    BrowserModule,
    HttpClientModule,
    NgxMdModule.forRoot(),
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})

index.html

If you want syntax highlighting you need to import the prism css file.

Alternative 1: Import from cdn

<head>
    <meta charset="utf-8">
    <base href="/">

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/themes/prism.min.css" rel="stylesheet" />
  </head>

Alternative 2: Download the css file (or copy it from node_modules/prismjs/themes/, place it somewhere in your src folder and import

<link href="/css/prism.min.css" rel="stylesheet" />

Alternative 3: Include the prism css file in your sass style file

@import 'prismjs/themes/prism.css';

To support sytnax helight for other langugage you need to include

// import 'prismjs/prism';
import 'prismjs/components/prism-c';
import 'prismjs/components/prism-cpp';
import 'prismjs/components/prism-csharp';
import 'prismjs/components/prism-css';
import 'prismjs/components/prism-diff';
import 'prismjs/components/prism-java';
import 'prismjs/components/prism-javascript';
import 'prismjs/components/prism-perl';
...
...
...

app.component.html

<div Markdown>
    ### your markdown code
</div>

<!-- or use angular component -->

<ngx-md>
    ### your markdown code
</ngx-md>

<!-- to load from remote URL -->

<div NgxMd [path]="'/path/to/readme.md'" (error)="errorHandler($event)" (loaded)="loadedHandler($event)" (rendered)="renderedHandler($event)"></div>

<!-- load remote source code with auto syntax highlighting -->

<ngx-md [path]="'/path/to/code.cpp'"></ngx-md>

<ngx-md [path]="'/path/to/code.java'"></ngx-md>

<!-- load remote source code from url stored in variable
(see additional details about variable binding in the next section) -->

<ngx-md [path]="urlVariable"></ngx-md>

<ngx-md [path]="urlVariable" (loaded)="onLoad($event)" (error)="onError($event)"></ngx-md>

Variable binding

Now, with >1.4.x you can bind a variable to the markdown component. To do so:

@Component({
    selector: 'app-root',
    template: `
    <textarea [(ngModel)]="textData"></textarea>
    <ngx-md [data]="textData"></ngx-md>
    `,
})
export class MyComp {
  public textData = `## Markdown content data`;
}

Marked customization

Marked can be customized/extended by accessing the renderer from the MarkdownService:

import { NgxMdService } from 'ngx-md';
@Component({
    selector='my-comp',
    template: `
    <ngx-md>
     > Block
     > quote
     > here
    </ngx-md>
    `,
})
export class MyComp {
  constructor(private _markdown: NgxMdService) {}

  ngOnInit() {
    this._markdown.renderer.blockquote = (quote: string) => {
      return `<blockquote class="king-quote">${quote}</blockquote>`;
    }
  }

See marked documentation for all renderer extension points.

Example

You can find a working example inside the demo directory.

To serve it locally, run:

git clone https://github.com/dimpu/ngx-md.git

npm i

npm run demo.serve

Todo

  • Variable binding
  • Code refactor
  • Write more unit tests
  • Angular 5,6,7 support
  • Angular schemantics support
  • Module configuration for markdown settings
  • Module configuration for prismjs settings

FOSSA Status

Contributors

The following is a list of all the people that have helped build this project. Thanks for your contributions!

glenngr glenngr paullryan

License

FOSSA Status

ngx-md's People

Contributors

anandchakru avatar angular-cli avatar bob-lee avatar damiandennis avatar danielsogl avatar dependabot[bot] avatar derektbrown avatar dimpu avatar dirkgroenen avatar fossabot avatar furknyavuz avatar glenngr avatar h3xx avatar hmagrini avatar jrista avatar mhamern avatar nikaple avatar nikoroberts avatar paullryan avatar rimesc avatar sebastianstehle avatar sguiheux avatar tooshar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar

ngx-md's Issues

Implicit type any throws errors when using webpack

I am using Angular 2.2.3 and I am building the whole thing with webpack. When I try to build I get

ERROR in C:...\node_modules\angular2-markdown\src\app\markdown\markdown.service.ts
(9,14): error TS7006: Parameter 'path' implicitly has an 'any' type.

ERROR in C:...\node_modules\angular2-markdown\src\app\markdown\markdown.component.ts
(84,41): error TS7006: Parameter 'line' implicitly has an 'any' type.

I tried setting both parameters to any and to string, unfortunately neither worked for me.

Is it possible to have a live preview?

      <textarea rows="10" cols="50" [(ngModel)]="textInput">
        </textarea>
      <markdown>
        {{textInput}}
      </markdown>

Is it possible to have something like this working ?
I don't think this is working.

Cache remote fetched resources

Good morning,
is there a way to prefetch remote markdown files i.e. on application startup and cache them to display later without another GET?
In my app main loading time is no big issue and i want to show those resources as fast as possible.

Cheers,
midzer

Failed to load resource

Hello,

I followed the instructions in the README but I get this error in the browser:

Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/angular2-markdown

I mapped
'angular2-markdown': 'node_modules/:angular2-markdown/index.ts',

in my systemjs.config.js but then I get another error

Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/node_modules/angular2-markdown/src/app/markdown/markdown.module

I tried adding the relevant map to systemjs.config.ts but it didn't work.

Thanks

[universal] Prism.highlightAll references `document`

MarkdownComponent is currently making 3 calls to Prism.highlightAll:

This causes an error during server compilation, as document doesn't exist:

ERROR ReferenceError: document is not defined
    at Object.highlightAll

A possible solution is to only run that method when in browser using isPlatformBrowser from @angular/common since, save for when the user has javascript disabled, Angular will take over on the client-side an re-render the component thus calling highlightAll.

I'm more than happy to add a PR for this or discuss other possible solutions.

Thanks!

Can't resolve 'rxjs/RX' in markdown.service.ts

ERROR in ./~/angular2-markdown/src/app/markdown/markdown.service.ts
Module not found: Error: Can't resolve 'rxjs/RX' in 'project/node_modules/angular2-markdown/src/app/markdown'
 @ ./~/angular2-markdown/src/app/markdown/markdown.service.ts 12:0-17
 @ ./~/angular2-markdown/src/app/markdown/markdown.module.ts
 @ ./~/angular2-markdown/index.ts
 @ ./src/app/app.module.ts
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi main

No ideia why i am getting this.

Using angular2-markdown insinde node_modules folder

I want to use the markdown module inside my node_modules folder to parse some README.md files in some reusable components inside an external module. I tried to import the MarkdownModule with import {MarkdownModule} from "angular2-markdown"; inside my external.module.ts file in the node_modules folder. I also added the MarkdownModule.forRoot() to my imports inside the @NgModule decorator. When I use <markdown> ##Example## </markdown> inside an HTML file in my module, i receive the following error:

Unhandled Promise rejection: Template parse errors:
'markdown' is not a known element:
1. If 'markdown' is an Angular component, then verify that it is part of this module.
2. If 'markdown' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message.

Pointing to my Tag

Is it possible to use the markdown module inside the node_modules folder or do I have to find another way to parse my README.md files?

Cannot build using AOT

By building Angular2 app worked perfectly until I installed angular2-markdown.

Here is the error at compilation time:

ERROR in Error encountered resolving symbol values statically. Calling function 'makeParamDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol Injectable in node_modules/angular2-markdown/node_modules/@angular/core/src/di/metadata.d.ts, resolving symbol OpaqueToken in node_modules/angular2-markdown/node_modules/@angular/core/src/di/opaque_token.d.ts, resolving symbol OpaqueToken in node_modules/angular2-markdown/node_modules/@angular/core/src/di/opaque_token.d.ts

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'src'
@ ./src/main.ts 5:0-74
@ multi main

ERROR in .//@angular/core/src/linker/system_js_ng_module_factory_loader.js
Module not found: Error: Can't resolve 'src$$_gendir' in 'node_modules@angular\core\src\linker'
@ ./
/@angular/core/src/linker/system_js_ng_module_factory_loader.js 71:15-36 87:15-102
@ .//@angular/core/src/linker.js
@ ./
/@angular/core/src/core.js
@ ./~/@angular/core/index.js
@ ./src/main.ts
@ multi main

Removing the angular2-markdown module solves the problem but I need it.

Get error after adding

I install the model via npm and added it to app.module.ts. But after this my hole up crashed. After removing it from imports in app.module everything runs fine again. Do I miss something or is it an error inside angular2-markdown? Without the markdown lib everything runs without an error message.

`Error: (SystemJS) expected expression, got '<'
@http://localhost:3000/app/app.module.js:15:27
@http://localhost:3000/app/app.module.js:1:31
@http://localhost:3000/app/app.module.js:1:2
@http://localhost:3000/app/main.js:7:20
@http://localhost:3000/app/main.js:1:31
@http://localhost:3000/app/main.js:1:2
ZoneDelegate.prototype.invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:391:17
Zone.prototype.run@http://localhost:3000/node_modules/zone.js/dist/zone.js:141:24
scheduleResolveOrReject/<@http://localhost:3000/node_modules/zone.js/dist/zone.js:831:52
ZoneDelegate.prototype.invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:424:17
Zone.prototype.runTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:191:28
drainMicroTaskQueue@http://localhost:3000/node_modules/zone.js/dist/zone.js:595:25
ZoneTask.invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:502:21
invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:1364:9
globalZoneAwareCallback@http://localhost:3000/node_modules/zone.js/dist/zone.js:1382:17

Evaluating http://localhost:3000/angular2-markdown
Evaluating http://localhost:3000/app/app.module.js
Evaluating http://localhost:3000/app/main.js
Error loading http://localhost:3000/app/main.js

Stack trace:
(SystemJS) expected expression, got '<'
@http://localhost:3000/app/app.module.js:15:27
@http://localhost:3000/app/app.module.js:1:31
@http://localhost:3000/app/app.module.js:1:2
@http://localhost:3000/app/main.js:7:20
@http://localhost:3000/app/main.js:1:31
@http://localhost:3000/app/main.js:1:2
ZoneDelegate.prototype.invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:391:17
Zone.prototype.run@http://localhost:3000/node_modules/zone.js/dist/zone.js:141:24
scheduleResolveOrReject/<@http://localhost:3000/node_modules/zone.js/dist/zone.js:831:52
ZoneDelegate.prototype.invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:424:17
Zone.prototype.runTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:191:28
drainMicroTaskQueue@http://localhost:3000/node_modules/zone.js/dist/zone.js:595:25
ZoneTask.invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:502:21
invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:1364:9
globalZoneAwareCallback@http://localhost:3000/node_modules/zone.js/dist/zone.js:1382:17

Evaluating http://localhost:3000/angular2-markdown
Evaluating http://localhost:3000/app/app.module.js
Evaluating http://localhost:3000/app/main.js
Error loading http://localhost:3000/app/main.js`

Remote URL usage

Hi.

It appears instructions to use markdown differ from README and Website:

<div Markdown [path]="/path/to/readme.md"></div>
<markdown [path]="/path/to/code.cpp"></markdown>
<markdown [path]="/path/to/code.java"></markdown>

versus

<markdown [path]="'/assets/files/demo.md'"> </markdown>
<div Markdown [path]="'/assets/files/demo.html'"> </div>
<div Markdown [path]="'/assets/files/demo.cpp'"> </div>
<div Markdown [path]="'/assets/files/demo.java'"> </div>

Either way my files are parsed but dont show translation from markdown language to HTML (i.e. # to <h1>). I followed tutorial at https://github.com/dimpu/angular2-markdown/blob/master/docs/getting-started/ng-cli.md carefully and there are no errors. Someone got a clue what am i missing?

Cheers,
midzer

404 Error Trying to Load the Package

I keep getting a 404 trying to load the markdown module into my application. I understand the TypeScript module resolution behaves much like Node in that it will traverse directories up the stack until if finds the module it's looking for (looking in module.ts, package.json, or index.ts respectively). With that being said, I've added your package to my project (which is essentially the angular2 quickstart at its' base), but I'm getting a 404 on the node_modules/angular2-markdown GET call. Here's my setup (only showing what's applicable to the issue) :

tsconfig.json

`"compilerOptions": {
    ......
   "moduleResolution": "node".
    ......
}`

systemjs.config.js

`(function (global) {
    System.config({
        paths: {
            // paths serve as alias
            'npm:': 'node_modules/'
        },
        // map tells the System loader where to look for things
        map: {
            ......
            'angular2-markdown': 'npm:angular2-markdown'
            .......
        });
})(this);`

package.json

`{
    ......
    "dependencies": {
        ......
        "angular2-markdown": "^1.3.5",
        ......
}`

app.module.js

`import { MarkdownModule } from 'angular2-markdown';
......
@NgModule({
    declarations: [
        ......
    ],
    imports:    [
        ......,
        MarkdownModule.forRoot()
    ],
    ......
export class AppModule { }`

The angular2-markdown package sits in the 'node_modules/angular2-markdown' directory. Inside the root of that package is the index.ts class. Since the package.json doesn't contain a "typings" property, the compiler should be using the index.ts, which contains:

index.ts

export * from './src/app/markdown/markdown.module';
export * from './src/app/markdown/markdown.component';

So, as you can see, the 'angular2-markdown' package is aliased to the node_modules directory in my project, but unfortunately when I try and grab the MarkdownModule I get the following error in my console:

GET http://localhost:3000/node_modules/angular2-markdown/ 404 (Not Found)

It looks as if the compiler isn't actually reading the index.ts. I've tried several things to try and brute force this thing to work. For example:

systemjs.config

  • Map directly to 'node_modules/angular2-markdown/index'
  • Map directly to 'node_modules/angular2-markdown/index.ts'

app.module.ts

  • Import the module directly from 'node_modules/angular2-markdown/index'
  • Import the module directly from 'node_modules/angular2-markdown/index.ts' (which I knew obviously wouldn't work, but at this point I'm out of ideas)

Suffice it to say none of that worked and I'm not sure what the problem is. Can anyone shed some light on this issue for me? I just started using Angular2, but I feel like this is more of a build issue than a library issue. Thanks in advance.

Error importing module for root

The import statement works:
import { MarkdownModule } from 'angular2-markdown';

However as soon as I add:
MarkdownModule.forRoot(),
to my imports, I get this error:
Uncaught Error: Cannot find module 'angular2-markdown'

Where the error happens when tracing it back:

// This function will be called whenever a module identifier that hasn't   // 20
// been installed is required. For backwards compatibility, and so that we
// can require binary dependencies on the server, we implement the         // 22
// fallback in terms of Npm.require.                                       // 23
options.fallback = function (id, parentId, error) {                        // 24
  // For simplicity, we honor only top-level module identifiers here.      // 25
  // We could try to honor relative and absolute module identifiers by     // 26
  // somehow combining `id` with `dir`, but we'd have to be really careful
  // that the resulting modules were located in a known directory (not     // 28
  // some arbitrary location on the file system), and we only really need  // 29
  // the fallback for dependencies installed in node_modules directories.  // 30
  if (topLevelIdPattern.test(id)) {                                        // 31
    if (typeof Npm === "object" &&                                         // 32
        typeof Npm.require === "function") {                               // 33
      return Npm.require(id);                                              // 34
    }                                                                      // 35
  }                                                                        // 36
                                                                           // 37
  throw error;                                                             // 38
};

At line #38, so topLevelIdPattern.test(id) is false!

Further context

Any hints on how to fix it? :)

Fenced Code Block not keeping spacing/formatting

The purpose of the fenced code block in markdown is to designate language formatting and keep exact spacing and formatting.

When the markdown is compiled, the spacing within my code blocks is removed. This spacing is used to indent the lines and without it the code block is virtually useless.

Below is the code block using the Github markdown in this comment text:

function fancyAlert(arg) {
    if(arg) {
        $.facebox({div:'#foo'})
    }
}

Below is an image of what the code block looks like after being compiled with Angular2-Markdown:
screen shot 2017-04-18 at 19 50 26

As you can see, the Github formatted markdown keeps the spacing, while the Angular2-Markdown formatted markdown does not contain the spaces.

Am I missing a setting, or is this a bug as I have suspected?

I also posted this issue on the marked repo: markedjs/marked#885

Thanks.

MarkdownComponent.prepare removes indention

I have a markdown file that uses sometimes 4 whitespaces to indent code blocks.
When I feed this directly to marked, I get the desired results. But with the MarkdownComponent of this project, the code blocks are not rendered. After debugging through the code, I found the prepare method which removes the whitespaces and with it the whole intentional formatting.

In the closed issues, there seem to be several issues that are probably related, but it was always pointed to marked, when in fact the prepare method is the cause.
Examples: #47, #41, #38 , #36 , #35

Suggestion: Just return raw instead of modifying the text.

Nested list not displaying correctly

Nested md list not nesting html correctly

* Parent li
  * Child li

This example should become:

<li>
  Parent li
  <ul>
    <li>Child li</li>
  </ul>
</li>

But instead it becomes

<ul>
  <li>
    Parent li
  </li>
<ul>
<ul>
  <li>Child li</li>
</ul>

Cannot find module 'angular2-markdown'

When importing in app.module.ts as import { MarkdownModule } from 'angular2-markdown';
console error is: Cannot find module 'angular2-markdown'

When import statement is changed to import { MarkdownModule } from 'angular2-markdown/bundles';
Cannot find module 'angular2-markdown' error goes away.

When import statement is import { MarkdownModule } from 'angular2-markdown/bundles';
and @NgModule import is MarkdownModule.forRoot()

new console error is Can't resolve all parameters for MarkdownService: (?).

originalStack:
"Error: Can't resolve all parameters for MarkdownService: (?). at SyntaxError.ZoneAwareError (http://localhost:4200/vendor.bundle.js:147841:33) at SyntaxError.BaseError [as constructor] (http://localhost:4200/vendor.bundle.js:103421:16) at new SyntaxError (http://localhost:4200/vendor.bundle.js:11245:16) at CompileMetadataResolver._getDependenciesMetadata (http://localhost:4200/vendor.bundle.js:25641:31) at CompileMetadataResolver._getTypeMetadata (http://localhost:4200/vendor.bundle.js:25516:26) at CompileMetadataResolver._getInjectableMetadata (http://localhost:4200/vendor.bundle.js:25504:21) at CompileMetadataResolver.getProviderMetadata (http://localhost:4200/vendor.bundle.js:25746:40) at http://localhost:4200/vendor.bundle.js:25704:49 at Array.forEach (native) at CompileMetadataResolver._getProvidersMetadata (http://localhost:4200/vendor.bundle.js:25671:19) at CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/vendor.bundle.js:25355:50) at CompileMetadataResolver.getNgModuleSummary (http://localhost:4200/vendor.bundle.js:25211:52) at http://localhost:4200/vendor.bundle.js:25282:72 at Array.forEach (native) at CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/vendor.bundle.js:25269:49)"

Any thoughts on how to get module working?

Current dependencies:

marked is not a function

I'm trying to create a markdown editor in my angular2 project with this package and I have this important issue : " marked " is not a function . The error comes from those lines :

// comple markdown to html
public compile(data: string) {
return marked(data);
}

Do you have any idea what can I do to fix the issue ?

That's the way I create my markdown input in my component :

<textarea [(ngModel)]="textData" [ngModelOptions]="{standalone: true}"></textarea>
        <markdown [data]="textData"></markdown>

Fetching remote resources twice

Hi. Looking into network tab of Chromium development console, it appears remote markdown files are fetched twice:

Remote resources fetching twice

It was included single time via <markdown [path]="'assets/markdown/index.md'"></markdown>.
Using line <div Markdown [path]="'assets/markdown/index.md'"></div> had same effect.

Is it an issue in zone.js?

Cheers,
midzer

Error during build with newer angular-cli

More recent versions of angular-cli fail to build when angular2-markdown is imported.

ERROR in Error encountered resolving symbol values statically. Calling function 
'makeDecorator', function calls are not supported. 
Consider replacing the function or lambda with a reference to an exported function, 
resolving symbol NgModule in 
/node_modules/angular2-markdown/node_modules/@angular/core/src/metadata/ng_module.d.ts, 
resolving symbol NgModule in 
/node_modules/angular2-markdown/node_modules/@angular/core/src/metadata.d.ts, 
resolving symbol NgModule in 
/node_modules/angular2-markdown/node_modules/@angular/core/src/core.d.ts, 
resolving symbol NgModule in 
/node_modules/angular2-markdown/node_modules/@angular/core/index.d.ts, 
resolving symbol MarkdownModule in 
/node_modules/angular2-markdown/src/app/markdown/markdown.module.ts, 
resolving symbol MarkdownModule in 
/node_modules/angular2-markdown/src/app/markdown/markdown.module.ts

Don't get an error if it's added when ng serve is already running, but a fresh ng build or ng serve will be halted on this error.

problems with < or >

hi, has anybody experienced problems when the markdown contains a code block with < or > ?

i get the following result:

image

I'm using your awesome directive like this:

image

where blogPost.text is a markdown string. Here the < and > are still ok.

Variable assignment fails

Assigning markdown to a variableas follows fails and just spews markdown back.

<markdown [data]="textData"></markdown>

If I embed markdown as follows it works.

<markdown>## Test</markdown>

Using version 1.6.0

empty line is removed

Hi there,

Why all the empty lines in the source .md file are not rendered in the result page?

I also checked the demo of this repository, it has the same issue.

Are there any reasons behind it? And how to resolve it if I need the empty lines?

thanks

-John

Build errors

angular-cli: 1.0.0-beta.26
node: 7.4.0
os: darwin x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7
@angular/compiler-cli: 2.4.7
angular2-markdown 1.3.10

I get the following errors when trying to build:
ERROR in Error encountered resolving symbol values statically. Calling function 'MarkdownModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in ......

Ability to extend Renderer

Given that your using marked.js and it's designed to be extended it would be beneficial to have direct access to the renderer (via the service). So maybe export the service and give an accessor to the direct renderer so users can extend the rendering functionality (for example I need to have more control over image rendering which I can do in marked via the renderer by extending the image syntax).

Custom css for markdown

Hi again,
i want to style my markdown files in a custom way.

For code syntax i would prefer any prism.css for sure. In my case i want to treat some <a> in a special way.

How do i achieve that?
Including an own markdownstyle.css globally with

a {
  text-decoration: none;
}

for example would override any <a> in my whole app.

Thanks for your support and have a friendly weekend,
midzer

Using Mathjax with Markdown

We want to use formula inside the markdown.. is it possible to add mathjax with this plugin which can render formulas too?

Thanks

Getting Build Errors

Angular2-Markdown: 1.3.8 (latest)
Node Version: 7.4.0
NPM Version: 4.0.5
Webpack Version: 2.2.1

resolve './src/app/markdown/markdown.module' in '/home/site/public_html/client/node_modules/angular2-markdown/bundles'
  using description file: /home/site/public_html/client/node_modules/angular2-markdown/package.json (relative path: ./bundles)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /home/site/public_html/client/node_modules/angular2-markdown/package.json (relative path: ./bundles)
    using description file: /home/site/public_html/client/node_modules/angular2-markdown/package.json (relative path: ./bundles/src/app/markdown/markdown.module)
      as directory
        /home/site/public_html/client/node_modules/angular2-markdown/bundles/src/app/markdown/markdown.module doesn't exist
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /home/site/public_html/client/node_modules/angular2-markdown/bundles/src/app/markdown/markdown.module doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        /home/site/public_html/client/node_modules/angular2-markdown/bundles/src/app/markdown/markdown.module.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        /home/site/public_html/client/node_modules/angular2-markdown/bundles/src/app/markdown/markdown.module.js doesn't exist
      .css
        Field 'browser' doesn't contain a valid alias configuration
        /home/site/public_html/client/node_modules/angular2-markdown/bundles/src/app/markdown/markdown.module.css doesn't exist
      .html
        Field 'browser' doesn't contain a valid alias configuration
        /home/site/public_html/client/node_modules/angular2-markdown/bundles/src/app/markdown/markdown.module.html doesn't exist
      .scss
        Field 'browser' doesn't contain a valid alias configuration
        /home/site/public_html/client/node_modules/angular2-markdown/bundles/src/app/markdown/markdown.module.scss doesn't exist

Any idea how I can resolve this? The src/ folder that used to be pulled in with the package is missing in this version, causing errors.

angular2-markdown package works on localhost but when I deploy on GitHub pages it gives me an error

Situation

I develop a site with Angular-CLI and will publish that on GitHub pages. the link to my project is https://heinpauwelyn.github.io.

I've installed a package named angular2-markdown to render markdown files on my HTML pages. Below you see my code:

<div class="container">
    <div class="row">
        <div class="col-md-8">
            <h2>Internship</h2>
            <!-- Below you see the `markdown` tag to render the markdown file -->
            <markdown path="/reports/intro.md"></markdown>
        </div>
        <div class="col-md-4">
            <app-reportslist></app-reportslist>
        </div>
    </div>
</div>

To test the site on localhost I use this command:

ng serve

This command gives no problem and render the markdown files good.

The problem

An error will be throw when I use command below to deploy my website on GitHub pages.

ng github-pages:deploy

This gives me next error:

ERROR in MarkdownModule is not an NgModule

Here is my code in my app.module.ts:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
     
import { MarkdownModule } from 'angular2-markdown';
import { AppComponent } from './app.component';
     
@NgModule({
    declarations: [AppComponent],
    imports: [
        BrowserModule,
        MarkdownModule
    ],
    bootstrap: [AppComponent],
})
export class AppModule { }

I've tried

Attempt one

I know on the guide stands that I must use MarkdownModule.forRoot(). If I use now ng serve, I've got this error:

ERROR in Error encountered resolving symbol values statically. Calling function MarkdownModule, function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in C:/***/heinpauwelyn.github.io/src/app/app.module.ts.

ERROR in C:/***/heinpauwelyn.github.io/src/app/app.module.ts: Property forRoot does not exist on type typeof MarkdownModule.

Attempt two

If I comment the line export class AppModule() like in the guide, I got this error:

ERROR in C:/***/heinpauwelyn.github.io/src/main.ts: Module C:/***/heinpauwelyn.github.io/src/app/app.module.ts has no exported member AppModule.

ERROR in C:/***/heinpauwelyn.github.io/src/app/app.module.ts: Declaration expected.

What is normal of course.

Question

How could I solve this problem?

Note: See also my question on Stack Overflow

Thanks in advance.

@type/PrismJS is not a module error.

Hi, I am trying to use this directive module in my little project, but when I import and compile with angular-cli, it shows:
ERROR in [default] node_modules/angular2-markdown/src/app/markdown/markdown.directive.ts:5:23
File 'node_modules/@types/PrismJS/index.d.ts' is not a module.

I have tried to make prism type be a module with:
export = Prism;

It can be compiled, BUT it can't work either.

In the console:
Uncaught Error: Unexpected value 'MarkdownModule' imported by the module 'PublishModule'

Any advice for solving this problem will be appreciated.

Cannot find name 'Prism'

I'm using Angular2 CLI (https://cli.angular.io) to create a new project. But when using this lib and run ng serve, it throwed:

.../node_modules/angular2-markdown/src/app/markdown/markdown.component.ts:65:13 Cannot find name 'Prism'.

The Markdown still works but maybe it can not highlight the code.

Formatting of text not as desired

Hi,

i like this project. Tried to use it with Angular and Material2 Beta. I'd like to show the markup in an MdDialog in the content area.

This is the preview from my Visual Studio Markup Addin:
image

This is the result in the application:
image

Someone any idea what i'm doing wrong. The 'mat-dialog-content' style has only set the margins set.

Many thanks in advance.
Regards Jens.

Implicit any type when use noImplicitAny typescript config flag

ERROR in [default] ../node_modules/angular2-markdown/src/app/markdown/markdown.component.ts:90:40
Parameter 'line' implicitly has an 'any' type.

ERROR in [default] ../node_modules/angular2-markdown/src/app/markdown/markdown.service.ts:10:13
Parameter 'path' implicitly has an 'any' type.

can't build

ionic2 use this add

imports: [
    BrowserModule,
    MarkdownModule.forRoot(),
]

Module build failed: Error: ENOENT: no such file or directory, open '/Users/zhengbin/Documents/Workspace/Ionic/cutePuppyPics/node_modules/angular2-markdown/index.js'
    at Error (native)

Spurious empty paragraphs added when binding to [data] property

When binding to the [data] property, the resulting HTML contains spurious empty paragraphs, which vanish if the markdown is updated. Depending on the CSS rules in effect, this can be observed as differences in spacing between the visible paragraphs, headings, etc.

You can actually observe the presence of these empty paragraphs in the source of the demo page, although in that case it has no visible effect on the spacing.

The problem seems to be that the variable binding occurs before ngAfterViewInit is called. By the time ngAfterViewInit is called, the generated HTML has already been set on the element and so it's treated as if it were inline markdown and processed a second time, resulting in the addition of empty paragraphs.

Addressed by pull request #59.

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.