Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(project): added angular (ngx-linkifyjs) documentation for linkifyjs #255

Open
wants to merge 11 commits into
base: gh-pages
Choose a base branch
from
251 changes: 251 additions & 0 deletions docs/linkify-angular-ts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
---
layout: doc
title: [ngx-linkifyjs](https://github.com/AnthonyNahas/ngx-linkifyjs) · Documentation
AnthonyNahas marked this conversation as resolved.
Show resolved Hide resolved
---

`ngx-linkifyjs` is an angular V7 wrapper for linkifyjs - library for finding links in plain text and converting them
AnthonyNahas marked this conversation as resolved.
Show resolved Hide resolved
to HTML <a> tags via linkifyjs and more <3
AnthonyNahas marked this conversation as resolved.
Show resolved Hide resolved

#### Jump to

* [Demo](#demo)
* [Installation](#installation)
* [Usage](#usage)
* [Pipe](#pipe) `NgxLinkifyjsPipe via | linkify`
* [Service](#service) `NgxLinkifyjsService`
* [Methods](#methods)
* [linkify _(text: string): string_](#linkify_method)
* [find](#find_method)
* [test](#test_method)
* [Configuration](#configuration)
* [Documentation](#documentation)


## Demo

View all the directives in action at [https://anthonynahas.github.io/ngx-linkifyjs](https://anthonynahas.github.io/ngx-linkifyjs)

## Installation


Install above dependencies via *npm*.
AnthonyNahas marked this conversation as resolved.
Show resolved Hide resolved

Now install `ngx-linkifyjs` via:
```shell
npm i -s ngx-linkifyjs
```

---
##### SystemJS
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
##### SystemJS
### SystemJS

>**Note**:If you are using `SystemJS`, you should adjust your configuration to point to the UMD bundle.
AnthonyNahas marked this conversation as resolved.
Show resolved Hide resolved
In your systemjs config file, `map` needs to tell the System loader where to look for `ngx-linkifyjs`:
```js
map: {
'ngx-linkifyjs': 'node_modules/ngx-linkifyjs/bundles/ngx-linkifyjs.umd.js',
}
```
---

Once installed you need to import the main module:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Once installed you need to import the main module:
Once installed, import the main module:

```js
import { NgxLinkifyjsModule } from 'ngx-linkifyjs';
```
The only remaining part is to list the imported module in your application module. The exact method will be slightly
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The only remaining part is to list the imported module in your application module. The exact method will be slightly
Finally, list the imported module in your application module. The exact method will

different for the root (top-level) module for which you should end up with the code similar to (notice ` NgxLinkifyjsModule .forRoot()`):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
different for the root (top-level) module for which you should end up with the code similar to (notice ` NgxLinkifyjsModule .forRoot()`):
vary for the root (top-level) module. You should have code similar to the following (notice `NgxLinkifyjsModule.forRoot()`):

```typescript
import { NgxLinkifyjsModule } from 'ngx-linkifyjs';

@NgModule({
declarations: [AppComponent, ...],
imports: [NgxLinkifyjsModule.forRoot(), ...],
bootstrap: [AppComponent]
})
export class AppModule {
}
```

Other modules in your application can simply import ` NgxLinkifyjsModule `:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Other modules in your application can simply import ` NgxLinkifyjsModule `:
Other modules in your application can import `NgxLinkifyjsModule`:


```js
import { NgxLinkifyjsModule } from 'ngx-linkifyjs';

@NgModule({
declarations: [OtherComponent, ...],
imports: [NgxLinkifyjsModule, ...],
})
export class OtherModule {
}
```


## Usage


Once the library is imported, you can use its components, directives and pipes in your Angular application:

### Pipe

`{{text | linkify}}`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to escape this line with the raw tag or Liquid will not render them:
image


```html
<span [innerHTML]="'Linkify the following URL: https://github.com/anthonynahas/ngx-linkifyjs and share it <3' | linkify"></span>
```

**result**: Linkify the following URL: [https://github.com/anthonynahas/ngx-linkifyjs](https://github.com/anthonynahas/ngx-linkifyjs) and share it <3

### Service

Inject the `NgxLinkifyjsService` service

```typescript
import {NgxLinkifyjsService, Link, LinkType} from 'ngx-linkifyjs';

constructor(public linkifyService: NgxLinkifyjsService) {
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra curly here.

Is the indentation correct? In Angular, can you have raw constructors like this?

```

#### Methods
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### Methods
### Methods


<a name="linkify_method"/>

#### linkify _(text: string): string_

Convert a basic text string to a valid linkified text

**Params**

* **`text`** : _`String`_ Text to linkify --> to convert with links

**Returns** _`String`_ converted text with links


```typescript
import {NgxLinkifyjsService, Link, LinkType} from 'ngx-linkifyjs';

constructor(public linkifyService: NgxLinkifyjsService) {
this.linkifyService.linkify('For help with GitHub.com, please email [email protected]');
// result --> see below
}
}
```

```typescript
'For help with <a href=\"http://github.com\" class=\"linkified\" target=\"_blank\">GitHub.com</a>, please email <a href=\"mailto:[email protected]\" class=\"linkified\">[email protected]</a>'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the double quotes should be escaped since this is a single-quoted string

Suggested change
'For help with <a href=\"http://github.com\" class=\"linkified\" target=\"_blank\">GitHub.com</a>, please email <a href=\"mailto:[email protected]\" class=\"linkified\">[email protected]</a>'
'For help with <a href="http://github.com" class="linkified" target="_blank">GitHub.com</a>, please email <a href="mailto:[email protected]" class="linkified">[email protected]</a>'

```

<a name="find_method"/>

#### find _(text: string): Array<Link>_

Finds all links in the given string

**Params**

* **`text`** : _`String`_ search text string
AnthonyNahas marked this conversation as resolved.
Show resolved Hide resolved

**Returns** _`Array<Link>`_ List of links where each element is a hash with properties type, value, and href:


* **type** is the type of entity found. Possible values are
- `'url'`
- `'email'`
- `'hashtag'` (if Hashtag is enabled via config/default `true`)
- `'mention'` (if Mention is enabled via config/default `true`)
* **value** is the original entity substring.
* **href** should be the value of this link's `href` attribute.

```typescript
import {Component, OnInit} from '@angular/core';
import {NgxLinkifyjsService, Link, LinkType} from 'ngx-linkifyjs';

@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent {

constructor(public linkifyService: NgxLinkifyjsService) {
const foundLinks: Link[] = this.linkifyService.find('Any links to github.com here? If not, contact [email protected]');

// result - output --> see below
}

}
```

```typescript
// Result
[
{
type: LinkType.URL,
value: 'github.com',
href: 'http://github.com'
},
{
type: LinkType.EMAIL,
value: '[email protected]',
href: 'mailto:[email protected]'
}
]
```

<a name="test_method"/>

#### test _(value: string | string[]: boolean_
AnthonyNahas marked this conversation as resolved.
Show resolved Hide resolved

Is the given string a link? Not to be used for strict validation - See [Caveats](caveats.html)

**Params**

* **`value`** : _`String`_ | _`Array<String>`_ Test string
AnthonyNahas marked this conversation as resolved.
Show resolved Hide resolved

**Returns** _`Boolean`_


```typescript
import {Component, OnInit} from '@angular/core';
import {NgxLinkifyjsService} from 'ngx-linkifyjs';

@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent {

constructor(public linkifyService: NgxLinkifyjsService) {
this.linkifyService.test('github.com'); // return true
this.linkifyService.test('[email protected]'); // return true
this.linkifyService.test(['github.com', 'email']); // return false
this.linkifyService.test('helloWorld'); // return false
}
}
```

#### Configuration


Enable/Disable the hash and mention
AnthonyNahas marked this conversation as resolved.
Show resolved Hide resolved

The config argument is 100% optional, otherwise we will take the default values `true`
AnthonyNahas marked this conversation as resolved.
Show resolved Hide resolved

```typescript
import { NgxLinkifyjsModule } from 'ngx-linkifyjs';

@NgModule({
declarations: [AppComponent, ...],
imports: [NgxLinkifyjsModule.forRoot(
{
enableHash: false, // optional - default true
enableMention: false // optional - default true
}), ...],
bootstrap: [AppComponent]
})
export class AppModule {
}
```

take a look @ [@angular-material-extensions/link-preview](https://github.com/angular-material-extensions/link-preview) which is using `ngx-linkifyjs`