<commit_before># Sanity Block Tools

Various tools for processing Sanity block content. Mostly used internally in the Studio code, but it got some nice functions (especially `htmlToBlocks`) which is handy when you are importing data from HTML into your dataset as block text.

## Example

Let's start with a complete example:

```js
import Schema from '@sanity/schema'
import blockTools from '@sanity/block-tools'


// Start with compiling a schema we can work against
const schema = Schema.compile({
  name: 'myBlog',
  types: [
    {
      type: 'object',
      name: 'blogPost',
      fields: [
        {
          title: 'Title',
          type: 'string',
          name: 'title'
        },
        {
          title: 'Body',
          name: 'body',
          type: 'array',
          of: [{type: 'block'}]<commit_msg>[block-tools] Add info about running sanity scripts (#1293)<commit_after># Sanity Block Tools

Various tools for processing Sanity block content. Mostly used internally in the Studio code, but it got some nice functions (especially `htmlToBlocks`) which is handy when you are importing data from HTML into your dataset as block text.

**NOTE:** If you want to use `@sanity/block-tools` in a Node.js script, make sure to run it with `sanity exec` (see [docs](https://www.sanity.io/docs/cli/exec)):

```sh
sanity exec path/to/script.js
```

## Example

Let's start with a complete example:

```js
import Schema from '@sanity/schema'
import blockTools from '@sanity/block-tools'


// Start with compiling a schema we can work against
const schema = Schema.compile({
  name: 'myBlog',
  types: [
    {
      type: 'object',
      name: 'blogPost',
      fields: [
        {
          title: 'Title',
          type: 'string',
          name: 'title'
        },
        {
          title: 'Body',
          name: 'body',
          type: 'array',
          of: [{type: 'block'}]
{'fraction_non_alphanumeric': 0.11298838437170011, 'fraction_numerical': 0.0021119324181626186, 'mean_word_length': 2.644230769230769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4026759', 'n_tokens_mistral': 556, 'n_tokens_neox': 530, 'n_words': 217}