1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
[](https://github.com/shaarli/netscape-bookmark-parser/releases)



Shaarli Netscape Bookmark Parser
================================
This library provides a decoder that is able of parsing Netscape bookmarks (as exported by common Web browsers and bookmarking services), and an encoder that is able to export data to bookmarks format.
🚀 Installation
---------------
Using [Composer](https://getcomposer.org/) ([package](https://packagist.org/packages/shaarli/netscape-bookmark-parser)):
```bash
$ composer require shaarli/netscape-bookmark-parser
```
🔥 Usage
--------
### Import from Bookmark file
```php
<?php
// parse.php
require_once 'vendor/autoload.php';
use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser;
$parser = new NetscapeBookmarkParser();
$bookmarks = $parser->parseFile('./tests/Fixtures/Encoder/input/netscape_basic.htm');
var_dump($bookmarks);
```
Above example will return following array:
```
array(2) {
[0] => array(7) {
["name"] => string(12) "Secret stuff"
["image"] => NULL
["url"] => string(19) "https://private.tld"
["tags"] => array(2) {
[0] => string(7) "private"
[1] => string(6) "secret"
}
["description"] => string(52) "Super-secret stuff you're not supposed to know about"
["dateCreated"] => int(971175336)
["public"] => bool(false)
}
[1] => array(7) {
["name"] => string(12) "Public stuff"
["image"] => NULL
["url"] => string(17) "http://public.tld"
["tags"] => array(3) {
[0] => string(6) "public"
[1] => string(5) "hello"
[2] => string(5) "world"
}
["description"] => NULL
["dateCreated"] => int(1456433748)
["public"] => bool(true)
}
}
```
### Export to file
```php
<?php
// export.php
require_once 'vendor/autoload.php';
use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser;
$data = [
[
'name' => 'shaarli/Shaarli',
'url' => 'https://github.com/shaarli/Shaarli',
'image' => 'data:image/png;base64, ...'
'description' => 'The personal, minimalist, super-fast, database free, bookmarking service',
'public' => true,
'tags' => ['shaarli'],
],
[
'name' => 'shaarli/netscape-bookmark-parser',
'url' => 'https://github.com/shaarli/netscape-bookmark-parser',
'public' => false,
'dateCreated' => '1612572000',
'dateModified' => '1612572000',
'tags' => ['shaarli'],
],
];
$parser = new NetscapeBookmarkParser();
$parser->export($data, './export.htm');
```
Above example will write following string into file:
```xml
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><H3>shaarli</H3>
<DL><p>
<DT><A HREF="https://github.com/shaarli/Shaarli" PRIVATE="0" ICON="data:image/png;base64, ...">shaarli/Shaarli</A>
<DD>The personal, minimalist, super-fast, database free, bookmarking service
<DT><A HREF="https://github.com/shaarli/netscape-bookmark-parser"> ADD_DATE="1612572000" LAST_MODIFIED="1612572000">shaarli/netscape-bookmark-parser</A>
<\DL><p>
<\DL><p>
```
💻 Dependencies
---------------
**Shaarli Netscape Bookmark Parser** requires the following dependencies:
- PHP
- Composer
- Make (optional)
---
### 🐘 PHP
Learn how to install PHP from official documentation [here](https://www.php.net/manual/en/install.php)
---
### 📦 Composer
Learn how to install Composer from official documentation [here](https://getcomposer.org/download/)
---
### 🛠 Make
#### 🐧 Install Make (Linux)
On linux machine enter following command
```bash
$ sudo apt-get install --assume-yes make
```
#### 🏁 Install Make (Windows)
On windows machine you will need to install [cygwin](http://www.cygwin.com/) or [GnuWin make](http://gnuwin32.sourceforge.net/packages/make.htm) first to execute make script.
#### 🍎 Install Make (OSX)
Make should be available by default on OSX system, but you can upgrade make version with following command
```bash
$ brew install make
```
---
📑 About
--------
### ⚡ A word from Kafene
The motivations behind developing this parser are the following:
- the [Netscape format](https://msdn.microsoft.com/en-us/library/aa753582%28v=vs.85%29.aspx) has a very loose specification: no [DTD](https://en.wikipedia.org/wiki/Document_type_definition) nor [XSL stylesheet](https://en.wikipedia.org/wiki/XSL) to constrain how data is formatted.
- software and web services export bookmarks using a wild variety of attribute names and values.
- using standard SAX or DOM parsers is thus not straightforward.
How it works:
- the input bookmark file is trimmed and sanitized to improve parsing results
- the resulting data is then parsed using [PCRE](http://www.pcre.org/) patterns to match attributes and values corresponding to the most likely:
- attribute names: `description` vs. `note`, `tags` vs. `labels`, `date` vs. `time`, etc.
- data formats: `comma,separated,tags` vs. `space separated labels`, UNIX epochs vs. human-readable dates, newlines & carriage returns, etc.
- an associative array containing all successfully parsed links with their attributes is returned
### ⚡ Shaarli community fork
This friendly fork is maintained by the Shaarli community at https://github.com/shaarli/netscape-bookmark-parser and is used by the open-source [Shaarli](https://github.com/shaarli/Shaarli) bookmarking service. This is a community fork of the original [netscape-bookmark-parser](https://github.com/kafene/netscape-bookmark-parser) project by [Kafene](http://kafene.org/).
🤝 Contributing
---------------
Thank you for your interrest in contributing to **Shaarli Netscape Bookmark Parser**.
Please review the [code of conduct](./CODE_OF_CONDUCT.md) and [contribution guidelines](./CONTRIBUTING.md) before starting to work on any features.
If you want to open an issue, please check first if it was not [reported already](https://github.com/shaarli/netscape-bookmark-parser/issues) before creating a new one.
📜 License
----------
Copyrights (c) 2021 "Shaarli community"
[](LICENSE)
Distributed under the MIT license.
If you like **Shaarli Netscape Bookmark Parser** please star or tweet about it:
[](https://github.com/shaarli/netscape-bookmark-parser/stargazers)
[](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2Fshaarli%2Fnetscape-bookmark-parser)
🙏 Acknowledgements
-------------------
- [Shaarli Community](https://github.com/shaarli)
- [Kafene](https://github.com/kafene)
- [VirtualTam](https://github.com/virtualtam)
- [TangoMan75](https://github.com/TangoMan75)
|