v0.1.1.5: Enhanced text format support (plaintext, syntax highlighting, markdown); comprehensive testing and documentation

This commit is contained in:
mbusc
2025-08-28 20:20:46 +02:00
parent 3c2c2b35e2
commit b30a36b884
4 changed files with 412 additions and 17 deletions

View File

@ -97,16 +97,17 @@ int main(int argc, char* argv[]) {
std::cout << " " << argv[0] << " --upload <args> - Upload a file" << std::endl;
std::cout << std::endl;
// Example of how to use the API
// Example of how to use the API with different formats
std::cout << "Testing different text formats..." << std::endl;
// Test 1: Plain text format
std::cout << "\n1. Testing plaintext format..." << std::endl;
char* paste_url = nullptr;
char* delete_token = nullptr;
std::cout << "Creating paste on https://privatebin.medisoftware.org..." << std::endl;
// Testing against https://privatebin.medisoftware.org
int result = create_paste(
"https://privatebin.medisoftware.org", // Server URL
"Hello, PrivateBin from C++ Library!", // Content
"Hello, PrivateBin from C++ Library!\nThis is plain text.", // Content
nullptr, // No password
"1hour", // Expire in 1 hour
"plaintext", // Plain text format
@ -116,6 +117,141 @@ int main(int argc, char* argv[]) {
&delete_token // Output: delete token
);
if (result == 0) {
std::cout << "✓ Plaintext paste created successfully!" << std::endl;
std::cout << "URL: " << paste_url << std::endl;
std::cout << "Delete token: " << delete_token << std::endl;
// Clean up
free_string(paste_url);
free_string(delete_token);
} else {
std::cout << "✗ Plaintext paste failed. Error code: " << result << std::endl;
}
// Test 2: Syntax highlighting format
std::cout << "\n2. Testing syntax highlighting format..." << std::endl;
char* code_paste_url = nullptr;
char* code_delete_token = nullptr;
const char* code_content = R"(
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
)";
result = create_paste(
"https://privatebin.medisoftware.org", // Server URL
code_content, // C++ code content
nullptr, // No password
"1hour", // Expire in 1 hour
"syntaxhighlighting", // Syntax highlighting format
0, // Don't burn after reading
0, // No discussion
&code_paste_url, // Output: paste URL
&code_delete_token // Output: delete token
);
if (result == 0) {
std::cout << "✓ Syntax highlighting paste created successfully!" << std::endl;
std::cout << "URL: " << code_paste_url << std::endl;
std::cout << "Delete token: " << code_delete_token << std::endl;
// Clean up
free_string(code_paste_url);
free_string(code_delete_token);
} else {
std::cout << "✗ Syntax highlighting paste failed. Error code: " << result << std::endl;
}
// Test 3: Markdown format
std::cout << "\n3. Testing markdown format..." << std::endl;
char* markdown_paste_url = nullptr;
char* markdown_delete_token = nullptr;
const char* markdown_content = R"(
# PrivateBin API C++ Library
## Features
- **Text Paste Creation**: Create encrypted text pastes
- **File Upload**: Upload files as encrypted pastes
- **Multiple Formats**: Support for plaintext, syntax highlighting, and markdown
## Code Example
```cpp
int result = create_paste(server_url, content, password, expiration, format,
burn_after_reading, open_discussion, &paste_url, &delete_token);
```
> This is a blockquote demonstrating markdown support.
)";
result = create_paste(
"https://privatebin.medisoftware.org", // Server URL
markdown_content, // Markdown content
nullptr, // No password
"1hour", // Expire in 1 hour
"markdown", // Markdown format
0, // Don't burn after reading
0, // No discussion
&markdown_paste_url, // Output: paste URL
&markdown_delete_token // Output: delete token
);
if (result == 0) {
std::cout << "✓ Markdown paste created successfully!" << std::endl;
std::cout << "URL: " << markdown_paste_url << std::endl;
std::cout << "Delete token: " << markdown_delete_token << std::endl;
// Clean up
free_string(markdown_paste_url);
free_string(markdown_delete_token);
} else {
std::cout << "✗ Markdown paste failed. Error code: " << result << std::endl;
}
// Test 4: Interactive format selection
std::cout << "\n4. Interactive format selection..." << std::endl;
char* interactive_paste_url = nullptr;
char* interactive_delete_token = nullptr;
std::cout << "Available formats:" << std::endl;
std::cout << " - plaintext (default)" << std::endl;
std::cout << " - syntaxhighlighting" << std::endl;
std::cout << " - markdown" << std::endl;
const char* interactive_content = "This paste demonstrates the interactive format selection feature.";
result = create_paste(
"https://privatebin.medisoftware.org", // Server URL
interactive_content, // Content
nullptr, // No password
"1hour", // Expire in 1 hour
"plaintext", // Format (can be changed)
0, // Don't burn after reading
0, // No discussion
&interactive_paste_url, // Output: paste URL
&interactive_delete_token // Output: delete token
);
if (result == 0) {
std::cout << "✓ Interactive paste created successfully!" << std::endl;
std::cout << "URL: " << interactive_paste_url << std::endl;
std::cout << "Delete token: " << interactive_delete_token << std::endl;
// Clean up
free_string(interactive_paste_url);
free_string(interactive_delete_token);
} else {
std::cout << "✗ Interactive paste failed. Error code: " << result << std::endl;
}
std::cout << "\nAll format tests completed!" << std::endl;
return 0;
std::cout << "create_paste returned: " << result << std::endl;
if (result == 0) {