Skip to content

Commit 1cf5ffa

Browse files
committed
Handle messy md code samples containing neste code blocks and texts
1 parent 6bc7355 commit 1cf5ffa

File tree

241 files changed

+187
-2191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+187
-2191
lines changed

guides/front_end/front_end_integration.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Front-end integration — Meilisearch documentation
33
description: Create a simple front-end interface to search through your dataset after following Meilisearch's quick start.
44
---
5+
import GettingStartedFrontEndIntegrationMd from '/snippets/getting_started_front_end_integration_md.mdx';
56

67
# Front-end integration
78

@@ -16,6 +17,6 @@ Using [`instant-meilisearch`](https://github.com/meilisearch/instant-meilisearch
1617
3. Copy-paste one of the code samples above—either vanilla JavaScript, Vue 2, or React— and save the file
1718
4. Open `index.html` in your browser by double-clicking it in your folder
1819

19-
<CodeSamples id="getting_started_front_end_integration_md" />
20+
<GettingStartedFrontEndIntegrationMd />
2021

2122
You should now have a working front-end search interface. [Consult `instant-meilisearch`'s documentation for more information on how to further customize your search interface.](https://github.com/meilisearch/instant-meilisearch)

scripts/pull-code-samples.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,34 @@ async function processRepos() {
132132
const filePath = path.join(OUTPUT_DIR, `${operationName}.mdx`);
133133
const content = `
134134
<CodeGroup>
135-
${snippets.map(snippet => `
135+
${snippets.map(snippet => {
136+
// Split content into description and code if it contains a nested code block
137+
const parts = snippet.content.split('```');
138+
139+
if (parts.length > 1) { // handle samples with nested code blocks
140+
// Has description and code blocks
141+
const description = parts[0].trim();
142+
const codeBlocks = parts.slice(1);
143+
144+
// Join all parts back together, keeping the description at the top
145+
return `
146+
\`\`\`text ${snippet.label}
147+
${description}
148+
149+
${codeBlocks.map(block => {
150+
// Remove language identifier and code block markers to ensure Mintlify can parse it
151+
const cleanBlock = block.replace(/^[a-z]+\s*/, '').replace(/```$/, '');
152+
return cleanBlock;
153+
}).join('\n')}
154+
\`\`\``;
155+
} else {
156+
// Regular standard code block
157+
return `
136158
\`\`\`${snippet.lang} ${snippet.label}
137159
${snippet.content}
138-
\`\`\`
139-
`).join('\n')}
160+
\`\`\``;
161+
}
162+
}).join('\n')}
140163
</CodeGroup>
141164
`.trim();
142165

snippets/add_movies_json_1.mdx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ curl \
77
--data-binary @movies.json
88
```
99

10-
1110
```javascript JS
1211
const movies = require('./movies.json')
1312
client.index('movies').addDocuments(movies).then((res) => console.log(res))
1413
```
1514

16-
1715
```python Python
1816
import json
1917

@@ -22,15 +20,13 @@ movies = json.load(json_file)
2220
client.index('movies').add_documents(movies)
2321
```
2422

25-
2623
```php PHP
2724
$moviesJson = file_get_contents('movies.json');
2825
$movies = json_decode($moviesJson);
2926

3027
$client->index('movies')->addDocuments($movies);
3128
```
3229

33-
3430
```java Java
3531
import com.meilisearch.sdk;
3632
import org.json.JSONArray;
@@ -44,7 +40,6 @@ Index index = client.index("movies");
4440
index.addDocuments(moviesJson);
4541
```
4642

47-
4843
```ruby Ruby
4944
require 'json'
5045

@@ -53,7 +48,6 @@ movies = JSON.parse(movies_json)
5348
client.index('movies').add_documents(movies)
5449
```
5550

56-
5751
```go Go
5852
import (
5953
"encoding/json"
@@ -68,7 +62,6 @@ json.Unmarshal([]byte(file), &movies)
6862
client.Index("movies").AddDocuments(&movies)
6963
```
7064

71-
7265
```csharp C#
7366
// Make sure to add this using to your code
7467
using System.IO;
@@ -77,7 +70,6 @@ var jsonDocuments = await File.ReadAllTextAsync("movies.json");
7770
await client.Index("movies").AddDocumentsJsonAsync(jsonDocuments);
7871
```
7972

80-
8173
```rust Rust
8274
use meilisearch_sdk::{
8375
indexes::*,
@@ -111,7 +103,6 @@ fn main() { block_on(async move {
111103
})}
112104
```
113105

114-
115106
```swift Swift
116107
let path = Bundle.main.url(forResource: "movies", withExtension: "json")!
117108
let documents: Data = try Data(contentsOf: path)
@@ -126,12 +117,10 @@ client.index("movies").addDocuments(documents: documents) { (result) in
126117
}
127118
```
128119

129-
130120
```dart Dart
131121
// import 'dart:io';
132122
// import 'dart:convert';
133123
final json = await File('movies.json').readAsString();
134124
await client.index('movies').addDocumentsJson(json);
135125
```
136-
137126
</CodeGroup>

snippets/add_or_replace_documents_1.mdx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ curl \
1515
]'
1616
```
1717

18-
1918
```javascript JS
2019
client.index('movies').addDocuments([{
2120
id: 287947,
@@ -26,7 +25,6 @@ client.index('movies').addDocuments([{
2625
}])
2726
```
2827

29-
3028
```python Python
3129
client.index('movies').add_documents([{
3230
'id': 287947,
@@ -37,7 +35,6 @@ client.index('movies').add_documents([{
3735
}])
3836
```
3937

40-
4138
```php PHP
4239
$client->index('movies')->addDocuments([
4340
[
@@ -50,7 +47,6 @@ $client->index('movies')->addDocuments([
5047
]);
5148
```
5249

53-
5450
```java Java
5551
client.index("movies").addDocuments("[{"
5652
+ "\"id\": 287947,"
@@ -62,7 +58,6 @@ client.index("movies").addDocuments("[{"
6258
);
6359
```
6460

65-
6661
```ruby Ruby
6762
client.index('movies').add_documents([
6863
{
@@ -75,7 +70,6 @@ client.index('movies').add_documents([
7570
])
7671
```
7772

78-
7973
```go Go
8074
documents := []map[string]interface{}{
8175
{
@@ -89,7 +83,6 @@ documents := []map[string]interface{}{
8983
client.Index("movies").AddDocuments(documents)
9084
```
9185

92-
9386
```csharp C#
9487
var movie = new[]
9588
{
@@ -105,7 +98,6 @@ var movie = new[]
10598
await index.AddDocumentsAsync(movie);
10699
```
107100

108-
109101
```rust Rust
110102
let task: TaskInfo = client
111103
.index("movies")
@@ -122,7 +114,6 @@ let task: TaskInfo = client
122114
.unwrap();
123115
```
124116

125-
126117
```swift Swift
127118
let documentJsonString = """
128119
[
@@ -147,7 +138,6 @@ client.index("movies").addDocuments(documents: documents) { (result) in
147138
}
148139
```
149140

150-
151141
```dart Dart
152142
await client.index('movies').addDocuments([
153143
{
@@ -161,5 +151,4 @@ await client.index('movies').addDocuments([
161151
}
162152
]);
163153
```
164-
165154
</CodeGroup>

snippets/add_or_update_documents_1.mdx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ curl \
1313
]'
1414
```
1515

16-
1716
```javascript JS
1817
client.index('movies').updateDocuments([{
1918
id: 287947,
@@ -22,7 +21,6 @@ client.index('movies').updateDocuments([{
2221
}])
2322
```
2423

25-
2624
```python Python
2725
client.index('movies').update_documents([{
2826
'id': 287947,
@@ -31,7 +29,6 @@ client.index('movies').update_documents([{
3129
}])
3230
```
3331

34-
3532
```php PHP
3633
$client->index('movies')->updateDocuments([
3734
[
@@ -42,7 +39,6 @@ $client->index('movies')->updateDocuments([
4239
]);
4340
```
4441

45-
4642
```java Java
4743
client.index("movies").updateDocuments("[{
4844
+ "\"id\": 287947,"
@@ -52,7 +48,6 @@ client.index("movies").updateDocuments("[{
5248
);
5349
```
5450

55-
5651
```ruby Ruby
5752
client.index('movies').update_documents([
5853
{
@@ -63,7 +58,6 @@ client.index('movies').update_documents([
6358
])
6459
```
6560

66-
6761
```go Go
6862
documents := []map[string]interface{}{
6963
{
@@ -75,7 +69,6 @@ documents := []map[string]interface{}{
7569
client.Index("movies").UpdateDocuments(documents)
7670
```
7771

78-
7972
```csharp C#
8073
var movie = new[]
8174
{
@@ -84,7 +77,6 @@ var movie = new[]
8477
await index.UpdateDocumentsAsync(movie);
8578
```
8679

87-
8880
```rust Rust
8981
// Define the type of our documents
9082
#[derive(Serialize, Deserialize)]
@@ -105,7 +97,6 @@ let task: TaskInfo = client
10597
.unwrap();
10698
```
10799

108-
109100
```swift Swift
110101
let documentJsonString = """
111102
[
@@ -128,7 +119,6 @@ client.index("movies").updateDocuments(documents: documents) { (result) in
128119
}
129120
```
130121

131-
132122
```dart Dart
133123
await client.index('movies').updateDocuments([
134124
{
@@ -138,5 +128,4 @@ await client.index('movies').updateDocuments([
138128
}
139129
]);
140130
```
141-
142131
</CodeGroup>

snippets/analytics_event_bind_event_1.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ curl \
1414
"position": 0
1515
}'
1616
```
17-
1817
</CodeGroup>

snippets/analytics_event_bind_search_1.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ curl \
88
-H 'X-MS-USER-ID: MEILISEARCH_USER_ID' \
99
--data-binary '{}'
1010
```
11-
1211
</CodeGroup>

snippets/analytics_event_click_1.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ curl \
1313
"position": 0
1414
}'
1515
```
16-
1716
</CodeGroup>

snippets/analytics_event_conversion_1.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ curl \
1313
"position": 0
1414
}'
1515
```
16-
1716
</CodeGroup>

snippets/async_guide_canceled_by.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ client.getTasks(params: TasksQuery(canceledBy: [9, 15])) { result in
1010
}
1111
}
1212
```
13-
1413
</CodeGroup>

0 commit comments

Comments
 (0)