├── platform ├── ios │ ├── ImageMasters │ │ ├── Icon.sketch │ │ │ ├── fonts │ │ │ ├── version │ │ │ ├── Data │ │ │ └── QuickLook │ │ │ │ ├── Preview.png │ │ │ │ └── Thumbnail.png │ │ └── UITabBarIcons.sketch │ │ │ ├── version │ │ │ ├── fonts │ │ │ ├── Data │ │ │ └── QuickLook │ │ │ ├── Preview.png │ │ │ └── Thumbnail.png │ ├── Bypass │ │ ├── BypassTests │ │ │ ├── en.lproj │ │ │ │ └── InfoPlist.strings │ │ │ ├── BypassTests-Info.plist │ │ │ ├── BPParserTests.m │ │ │ ├── BPDocumentTests.mm │ │ │ └── BPElementTests.mm │ │ ├── Bypass │ │ │ ├── Bypass-Prefix.pch │ │ │ ├── BPParser.h │ │ │ ├── Bypass.h │ │ │ ├── BPElementPrivate.h │ │ │ ├── BPDocumentPrivate.h │ │ │ ├── BPImageGetter.h │ │ │ ├── BPDocument.h │ │ │ ├── BPParser.mm │ │ │ ├── BPMarkdownPageView.h │ │ │ ├── BPAttributedStringConverter.h │ │ │ ├── BPDisplaySettings.h │ │ │ ├── BPMarkdownView.h │ │ │ ├── BPDocument.mm │ │ │ ├── BPElement.h │ │ │ ├── BPDisplaySettings.m │ │ │ ├── BPMarkdownPageView.m │ │ │ └── BPElement.mm │ │ └── Bypass.xcodeproj │ │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ ├── images │ │ ├── target.png │ │ ├── buildPhases.png │ │ ├── buildSettings.png │ │ ├── dragXcodeproj.png │ │ ├── linkLibraries.png │ │ └── targetDependency.png │ ├── BypassSample │ │ ├── BypassSample │ │ │ ├── en.lproj │ │ │ │ ├── InfoPlist.strings │ │ │ │ └── MainStoryboard.storyboard │ │ │ ├── iPhone.png │ │ │ ├── Default.png │ │ │ ├── markdown.png │ │ │ ├── Default@2x.png │ │ │ ├── UITextView.png │ │ │ ├── UITextView@2x.png │ │ │ ├── iPhone Retina.png │ │ │ ├── BPMarkdownView.png │ │ │ ├── Default-568h@2x.png │ │ │ ├── BPMarkdownView@2x.png │ │ │ ├── BPAbstractViewController.h │ │ │ ├── BPImageGetterSample.h │ │ │ ├── BPMarkdownViewController.h │ │ │ ├── BypassSample-Prefix.pch │ │ │ ├── BPImageGetterSample.m │ │ │ ├── main.m │ │ │ ├── sample.markdown │ │ │ ├── BPMarkdownViewController.m │ │ │ ├── BPAbstractViewController.m │ │ │ ├── BPTextViewController.h │ │ │ ├── BPAppDelegate.h │ │ │ ├── BypassSample-Info.plist │ │ │ ├── BPAppDelegate.m │ │ │ └── BPTextViewController.mm │ │ ├── BypassSampleTests │ │ │ ├── en.lproj │ │ │ │ └── InfoPlist.strings │ │ │ ├── BypassSampleTests.h │ │ │ ├── BypassSampleTests.m │ │ │ └── BypassSampleTests-Info.plist │ │ ├── iPhone.png │ │ ├── iPhone Retina.png │ │ └── BypassSample.xcodeproj │ │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── README.md └── android │ ├── .gitignore │ ├── library │ ├── jni │ │ ├── Application.mk │ │ ├── Android.mk │ │ ├── in_uncod_android_bypass_Bypass.h │ │ └── bypass.cpp │ ├── res │ │ └── values │ │ │ └── strings.xml │ ├── src │ │ └── in │ │ │ └── uncod │ │ │ └── android │ │ │ └── bypass │ │ │ ├── Document.java │ │ │ ├── style │ │ │ └── HorizontalLineSpan.java │ │ │ ├── ReverseSpannableStringBuilder.java │ │ │ └── Element.java │ ├── AndroidManifest.xml │ ├── project.properties │ └── pom.xml │ ├── functional-test │ ├── res │ │ ├── values │ │ │ └── strings.xml │ │ ├── drawable-hdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ │ └── ic_launcher.png │ │ ├── layout │ │ │ ├── main.xml~ │ │ │ └── main.xml │ │ └── raw │ │ │ └── readme.txt │ ├── project.properties │ ├── AndroidManifest.xml │ ├── src │ │ └── in │ │ │ └── uncod │ │ │ └── android │ │ │ └── bypass │ │ │ └── test │ │ │ └── BenchmarkActivity.java │ └── pom.xml │ ├── functional-test-tests │ ├── res │ │ ├── drawable-hdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-ldpi │ │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ │ └── ic_launcher.png │ │ └── values │ │ │ └── strings.xml │ ├── project.properties │ ├── AndroidManifest.xml │ ├── pom.xml │ └── src │ │ └── in │ │ └── uncod │ │ └── andrpod │ │ └── bypass │ │ └── bypass_test │ │ └── test │ │ └── BasicTests.java │ ├── README.md │ └── pom.xml ├── dep ├── Makefile └── libsoldout │ ├── LICENSE │ ├── expanded_markdown.sh │ ├── CHANGES │ ├── GNUmakefile │ ├── renderers.h │ ├── BSDmakefile │ ├── benchmark.c │ ├── markdown.h │ ├── array.h │ ├── buffer.h │ ├── mkd2html.c │ ├── mkd2man.c │ ├── buffer.c │ └── array.c ├── src ├── Makefile ├── document.h ├── document.cpp ├── element.h ├── parser.h └── element.cpp ├── Makefile ├── .gitignore ├── test ├── Makefile ├── document_tests.cpp └── element_tests.cpp ├── README.md ├── logo.svg └── LICENSE.txt /platform/ios/ImageMasters/Icon.sketch/fonts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /platform/ios/ImageMasters/Icon.sketch/version: -------------------------------------------------------------------------------- 1 | 9 -------------------------------------------------------------------------------- /platform/android/.gitignore: -------------------------------------------------------------------------------- 1 | obj/ 2 | gen/ 3 | bin/ 4 | -------------------------------------------------------------------------------- /platform/ios/ImageMasters/UITabBarIcons.sketch/version: -------------------------------------------------------------------------------- 1 | 9 -------------------------------------------------------------------------------- /platform/ios/Bypass/BypassTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /platform/ios/images/target.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/images/target.png -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSampleTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/iPhone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/BypassSample/iPhone.png -------------------------------------------------------------------------------- /platform/ios/images/buildPhases.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/images/buildPhases.png -------------------------------------------------------------------------------- /platform/ios/images/buildSettings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/images/buildSettings.png -------------------------------------------------------------------------------- /platform/ios/images/dragXcodeproj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/images/dragXcodeproj.png -------------------------------------------------------------------------------- /platform/ios/images/linkLibraries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/images/linkLibraries.png -------------------------------------------------------------------------------- /platform/ios/images/targetDependency.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/images/targetDependency.png -------------------------------------------------------------------------------- /platform/ios/BypassSample/iPhone Retina.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/BypassSample/iPhone Retina.png -------------------------------------------------------------------------------- /platform/ios/ImageMasters/Icon.sketch/Data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/ImageMasters/Icon.sketch/Data -------------------------------------------------------------------------------- /platform/android/library/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := armeabi armeabi-v7a arm64-v8a x86 x86_64 mips mips64 2 | APP_STL := gnustl_static 3 | -------------------------------------------------------------------------------- /platform/android/functional-test/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Bypass-Test 4 | 5 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/iPhone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/BypassSample/BypassSample/iPhone.png -------------------------------------------------------------------------------- /platform/ios/ImageMasters/UITabBarIcons.sketch/fonts: -------------------------------------------------------------------------------- 1 | Helvetica 2 | SnellRoundhand 3 | Helvetica 4 | SnellRoundhand 5 | Helvetica 6 | SnellRoundhand -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/BypassSample/BypassSample/Default.png -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/markdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/BypassSample/BypassSample/markdown.png -------------------------------------------------------------------------------- /platform/ios/ImageMasters/UITabBarIcons.sketch/Data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/ImageMasters/UITabBarIcons.sketch/Data -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/BypassSample/BypassSample/Default@2x.png -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/UITextView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/BypassSample/BypassSample/UITextView.png -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/UITextView@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/BypassSample/BypassSample/UITextView@2x.png -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/iPhone Retina.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/BypassSample/BypassSample/iPhone Retina.png -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BPMarkdownView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/BypassSample/BypassSample/BPMarkdownView.png -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/BypassSample/BypassSample/Default-568h@2x.png -------------------------------------------------------------------------------- /platform/ios/ImageMasters/Icon.sketch/QuickLook/Preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/ImageMasters/Icon.sketch/QuickLook/Preview.png -------------------------------------------------------------------------------- /platform/android/library/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Bypass 4 | 5 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BPMarkdownView@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/BypassSample/BypassSample/BPMarkdownView@2x.png -------------------------------------------------------------------------------- /platform/ios/ImageMasters/Icon.sketch/QuickLook/Thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/ImageMasters/Icon.sketch/QuickLook/Thumbnail.png -------------------------------------------------------------------------------- /platform/android/functional-test/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/android/functional-test/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /platform/android/functional-test/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/android/functional-test/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /platform/android/functional-test/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/android/functional-test/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /platform/ios/ImageMasters/UITabBarIcons.sketch/QuickLook/Preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/ImageMasters/UITabBarIcons.sketch/QuickLook/Preview.png -------------------------------------------------------------------------------- /platform/ios/ImageMasters/UITabBarIcons.sketch/QuickLook/Thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/ios/ImageMasters/UITabBarIcons.sketch/QuickLook/Thumbnail.png -------------------------------------------------------------------------------- /platform/android/functional-test-tests/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/android/functional-test-tests/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /platform/android/functional-test-tests/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/android/functional-test-tests/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /platform/android/functional-test-tests/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/android/functional-test-tests/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /platform/android/functional-test-tests/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Uncodin/bypass/HEAD/platform/android/functional-test-tests/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /platform/android/functional-test-tests/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Bypass-Test-FrameworkTest 5 | 6 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/Bypass-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'Bypass' target in the 'Bypass' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /dep/Makefile: -------------------------------------------------------------------------------- 1 | LIBSOLDOUT_DIR = libsoldout 2 | 3 | .PHONY: all libsoldout clean 4 | 5 | all: libsoldout 6 | 7 | libsoldout: 8 | $(MAKE) -C $(LIBSOLDOUT_DIR) 9 | 10 | clean: 11 | $(MAKE) -C $(LIBSOLDOUT_DIR) clean 12 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | SRC = $(wildcard *.cpp) 2 | OBJ = $(SRC:.cpp=.o) 3 | CPPFLAGS = -Wall 4 | CXXFLAGS = -I../dep/libsoldout -g -O3 -fPIC 5 | 6 | .PHONY: all clean 7 | 8 | all: $(OBJ) 9 | 10 | %.o: %.cpp 11 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< 12 | 13 | clean: 14 | rm -f *.o 15 | rm -f *.a -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSampleTests/BypassSampleTests.h: -------------------------------------------------------------------------------- 1 | // 2 | // BypassSampleTests.h 3 | // BypassSampleTests 4 | // 5 | // Created by Damian Carrillo on 2/28/13. 6 | // Copyright (c) 2013 Uncodin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BypassSampleTests : SenTestCase 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SRC_DIR = src 2 | TEST_DIR = test 3 | DEP_DIR = dep 4 | 5 | .PHONY: all dep lib check clean 6 | 7 | all: check 8 | 9 | dep: 10 | $(MAKE) -C $(DEP_DIR) 11 | 12 | lib: dep 13 | $(MAKE) -C $(SRC_DIR) 14 | 15 | check: lib 16 | $(MAKE) -C $(TEST_DIR) 17 | 18 | clean: 19 | $(MAKE) -C $(TEST_DIR) clean 20 | $(MAKE) -C $(SRC_DIR) clean 21 | $(MAKE) -C $(DEP_DIR) clean 22 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BPAbstractViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPAbstractViewController.h 3 | // BypassSample 4 | // 5 | // Created by Damian Carrillo on 3/13/13. 6 | // Copyright (c) 2013 Uncodin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BPAbstractViewController : UIViewController 12 | 13 | - (NSString *)sampleMarkdown; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BPImageGetterSample.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPImageGetterSample.h 3 | // BypassSample 4 | // 5 | // Created by Victor Oliveira on 17/07/17. 6 | // Copyright © 2017 Uncodin. All rights reserved. 7 | // 8 | 9 | #import "BPImageGetter.h" 10 | 11 | @interface BPImageGetterSample : NSObject 12 | 13 | - (UIImage *) getUIImageWithSource:(NSString *)source; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /platform/android/library/src/in/uncod/android/bypass/Document.java: -------------------------------------------------------------------------------- 1 | package in.uncod.android.bypass; 2 | 3 | public class Document { 4 | 5 | Element[] elements; 6 | 7 | public Document(Element[] elements) { 8 | this.elements = elements; 9 | } 10 | 11 | public int getElementCount() { 12 | return elements.length; 13 | } 14 | 15 | public Element getElement(int pos) { 16 | return elements[pos]; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.a 3 | *.pbxuser 4 | *.mode1v3 5 | .DS_Store 6 | xcuserdata 7 | *.svn 8 | pulse.xml 9 | ivy.xml 10 | build.properties 11 | Version.txt 12 | build.xml 13 | .fseventsd 14 | .TemporaryItems 15 | *.o 16 | *.so 17 | *.so.1 18 | *.dSYM 19 | dep/libsoldout*/*.d 20 | dep/libsoldout-1.3/depends 21 | dep/libsoldout-1.3/mkd2html 22 | dep/libsoldout-1.3/mkd2latex 23 | dep/libsoldout-1.3/mkd2man 24 | test/*.tst 25 | *.class 26 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BPMarkdownViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPMarkdownViewController.h 3 | // BypassSample 4 | // 5 | // Created by Damian Carrillo on 3/13/13. 6 | // Copyright (c) 2013 Uncodin. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "BPAbstractViewController.h" 12 | 13 | @interface BPMarkdownViewController : BPAbstractViewController 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BypassSample-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'BypassSample' target in the 'BypassSample' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_5_0 8 | #warning "This project uses features only available in iOS SDK 5.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BPImageGetterSample.m: -------------------------------------------------------------------------------- 1 | // 2 | // BPImageGetterSample.m 3 | // BypassSample 4 | // 5 | // Created by Victor Oliveira on 17/07/17. 6 | // Copyright © 2017 Uncodin. All rights reserved. 7 | // 8 | 9 | #import "BPImageGetterSample.h" 10 | 11 | @implementation BPImageGetterSample 12 | 13 | - (UIImage *) getUIImageWithSource:(NSString *)source { 14 | 15 | return [UIImage imageNamed:source]; 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // BypassSample 4 | // 5 | // Created by Damian Carrillo on 2/28/13. 6 | // Copyright (c) 2013 Uncodin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "BPAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([BPAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /platform/android/functional-test/res/layout/main.xml~: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /platform/android/library/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /platform/android/functional-test/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /platform/android/library/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | BYPASS_SRC := ../../../../src/ 3 | 4 | include $(CLEAR_VARS) 5 | 6 | LOCAL_MODULE := bypass 7 | LOCAL_SRC_FILES := \ 8 | bypass.cpp \ 9 | $(BYPASS_SRC)parser.cpp \ 10 | $(BYPASS_SRC)document.cpp \ 11 | $(BYPASS_SRC)element.cpp \ 12 | ../../../../dep/libsoldout/markdown.c \ 13 | ../../../../dep/libsoldout/buffer.c \ 14 | ../../../../dep/libsoldout/array.c 15 | 16 | LOCAL_C_INCLUDES:= ../../../dep/libsoldout ../../../src /opt/local/include /usr/local/include $(BYPASS_INCLUDE_PATH) 17 | 18 | include $(BUILD_SHARED_LIBRARY) 19 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/sample.markdown: -------------------------------------------------------------------------------- 1 | #Header sizes 2 | ##Smaller header 3 | ###Even smaller header 4 | 5 | Paragraphs are obviously supported along with all the fancy text styling you could want. 6 | There is *italic*, **bold** and ***bold italic***. 7 | Even links are supported, visit the 8 | github page for Bypass [here](https://github.com/Uncodin/bypass). 9 | 10 | * Nested List 11 | * One 12 | * Two 13 | * Three 14 | * One 15 | * One 16 | * Two 17 | * Three 18 | 19 | ## Code Block Support 20 | 21 | const char* str; 22 | str = env->GetStringUTFChars(markdown, NULL); 23 | 24 | ## Image Support 25 | 26 | ![test](markdown.png) 27 | -------------------------------------------------------------------------------- /platform/android/functional-test-tests/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-16 15 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSampleTests/BypassSampleTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // BypassSampleTests.m 3 | // BypassSampleTests 4 | // 5 | // Created by Damian Carrillo on 2/28/13. 6 | // Copyright (c) 2013 Uncodin. All rights reserved. 7 | // 8 | 9 | #import "BypassSampleTests.h" 10 | 11 | @implementation BypassSampleTests 12 | 13 | - (void)setUp 14 | { 15 | [super setUp]; 16 | 17 | // Set-up code here. 18 | } 19 | 20 | - (void)tearDown 21 | { 22 | // Tear-down code here. 23 | 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample 28 | { 29 | STFail(@"Unit tests are not implemented yet in BypassSampleTests"); 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /platform/android/library/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | android.library=true 14 | # Project target. 15 | target=android-8 16 | -------------------------------------------------------------------------------- /platform/android/library/jni/in_uncod_android_bypass_Bypass.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class in_uncod_android_bypass_Bypass */ 4 | 5 | #ifndef _Included_in_uncod_android_bypass_Bypass 6 | #define _Included_in_uncod_android_bypass_Bypass 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: in_uncod_android_bypass_Bypass 12 | * Method: processMarkdown 13 | * Signature: (Ljava/lang/String;)Lin/uncod/android/bypass/Document; 14 | */ 15 | JNIEXPORT jobject JNICALL Java_in_uncod_android_bypass_Bypass_processMarkdown 16 | (JNIEnv *, jobject, jstring); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /platform/android/functional-test/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-17 15 | android.library.reference.1=../library 16 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | DEPOBJ = $(wildcard ../dep/libsoldout/*.o) 2 | SUTOBJ = $(wildcard ../src/*.o) 3 | SRC = $(wildcard *.cpp) 4 | OBJ = $(SRC:.cpp=.o) 5 | TESTS = $(SRC:.cpp=.tst) 6 | CPPFLAGS = -Wall 7 | CXXFLAGS = -I../src -I../dep/libsoldout -g -O3 -Wno-unknown-pragmas 8 | 9 | .PHONY: all clean check test 10 | .SECONDARY: 11 | 12 | all: check 13 | 14 | %.o: %.cpp 15 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< 16 | 17 | %.tst: %.o 18 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(addsuffix .tst,$(basename $<)) $(DEPOBJ) $(SUTOBJ) $^ 19 | 20 | test: $(TESTS) 21 | 22 | check: test 23 | for test in *.tst; do echo "• $${test}" && "./$${test}"; done 24 | 25 | clean: 26 | rm -f *.o 27 | rm -f *.tst 28 | rm -rf *.dSYM 29 | -------------------------------------------------------------------------------- /platform/android/functional-test-tests/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 12 | 13 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BPMarkdownViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // BPMarkdownViewController.m 3 | // BypassSample 4 | // 5 | // Created by Damian Carrillo on 3/13/13. 6 | // Copyright (c) 2013 Uncodin. All rights reserved. 7 | // 8 | 9 | #import "BPMarkdownViewController.h" 10 | 11 | @interface BPMarkdownViewController () 12 | @property (strong, nonatomic) IBOutlet BPMarkdownView *markdownView; 13 | @end 14 | 15 | @implementation BPMarkdownViewController 16 | 17 | - (void)viewWillAppear:(BOOL)animated 18 | { 19 | NSString *sampleMarkdown = [self sampleMarkdown]; 20 | [[self markdownView] setMarkdown:sampleMarkdown]; 21 | } 22 | 23 | - (void)viewDidAppear:(BOOL)animated 24 | { 25 | [[self markdownView] flashScrollIndicators]; 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /dep/libsoldout/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009, Natacha Porté 2 | 3 | Permission to use, copy, modify, and distribute this software for any 4 | purpose with or without fee is hereby granted, provided that the above 5 | copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /platform/ios/Bypass/BypassTests/BypassTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.uncodin.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSampleTests/BypassSampleTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.uncodin.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BPAbstractViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // BPAbstractViewController.m 3 | // BypassSample 4 | // 5 | // Created by Damian Carrillo on 3/13/13. 6 | // Copyright (c) 2013 Uncodin. All rights reserved. 7 | // 8 | 9 | #import "BPAbstractViewController.h" 10 | 11 | @interface BPAbstractViewController () 12 | 13 | @end 14 | 15 | @implementation BPAbstractViewController 16 | 17 | - (NSString *)sampleMarkdown 18 | { 19 | NSString *samplePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"markdown"]; 20 | 21 | NSError *error = nil; 22 | NSString *sample = [NSString stringWithContentsOfFile:samplePath encoding:NSUTF8StringEncoding error:&error]; 23 | 24 | if (error != nil) { 25 | NSLog(@"Error: %@", error); 26 | return nil; 27 | } 28 | 29 | return sample; 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /platform/android/functional-test/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 9 | 10 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPParser.h 3 | // Bypass 4 | // 5 | // Created by Damian Carrillo on 2/28/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "BPDocument.h" 23 | 24 | @interface BPParser : NSObject 25 | 26 | - (BPDocument *)parse:(NSString *)markdown; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/Bypass.h: -------------------------------------------------------------------------------- 1 | // 2 | // Bypass.h 3 | // Bypass 4 | // 5 | // Created by Damian Carrillo on 2/28/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "BPAttributedStringConverter.h" 22 | #import "BPElement.h" 23 | #import "BPDocument.h" 24 | #import "BPMarkdownView.h" 25 | #import "BPParser.h" 26 | #import "BPDisplaySettings.h" 27 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPElementPrivate.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPElementPrivate.h 3 | // Bypass 4 | // 5 | // Created by Damian Carrillo on 3/1/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "BPElement.h" 22 | #import "element.h" 23 | 24 | @interface BPElement (Private) 25 | 26 | - (id)init; 27 | - (id)initWithElement:(Bypass::Element)element; 28 | 29 | @end -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BPTextViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPTextViewController.h 3 | // BypassSample 4 | // 5 | // Created by Damian Carrillo on 3/1/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "BPAbstractViewController.h" 23 | 24 | @interface BPTextViewController : BPAbstractViewController 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BPAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPAppDelegate.h 3 | // BypassSample 4 | // 5 | // Created by Damian Carrillo on 3/1/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | 23 | @interface BPAppDelegate : UIResponder 24 | 25 | @property (strong, nonatomic) UIWindow *window; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPDocumentPrivate.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPDocumentPrivate.h 3 | // Bypass 4 | // 5 | // Created by Damian Carrillo on 3/1/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "BPDocument.h" 22 | #import "BPElementPrivate.h" 23 | #import "document.h" 24 | 25 | @interface BPDocument (Private) 26 | 27 | - (id)init; 28 | - (id)initWithDocument:(Bypass::Document)document; 29 | 30 | @end -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPImageGetter.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPImageGetter.h 3 | // Bypass 4 | // 5 | // Created by Victor Oliveira on 17/07/17. 6 | // Copyright © 2017 Uncodin. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #ifndef BPImageGetter_h 23 | #define BPImageGetter_h 24 | 25 | @protocol BPImageGetter 26 | 27 | @required 28 | - (UIImage *) getUIImageWithSource:(NSString *)source; 29 | 30 | @end 31 | 32 | #endif /* BPImageGetter_h */ 33 | -------------------------------------------------------------------------------- /src/document.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2013 Uncodin, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef BYPASS_DOCUMENT_H 18 | #define BYPASS_DOCUMENT_H 19 | 20 | #include 21 | #include "element.h" 22 | 23 | namespace Bypass 24 | { 25 | class Document 26 | { 27 | public: 28 | Document(); 29 | ~Document(); 30 | void append(const Element& elements); 31 | Element operator[](size_t i); 32 | size_t size(); 33 | private: 34 | std::vector elements; 35 | }; 36 | } 37 | 38 | #endif // BYPASS_DOCUMENT_H 39 | -------------------------------------------------------------------------------- /src/document.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2013 Uncodin, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #include "document.h" 18 | 19 | namespace Bypass { 20 | 21 | Document::Document() 22 | : elements() 23 | { 24 | 25 | } 26 | 27 | Document::~Document() { 28 | 29 | } 30 | 31 | void Document::append(const Element& element) { 32 | elements.push_back(Element(element)); 33 | } 34 | 35 | size_t Document::size() { 36 | return elements.size(); 37 | } 38 | 39 | Element Document::operator[](size_t i) { 40 | return elements[i]; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPDocument.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPDocument.h 3 | // Bypass 4 | // 5 | // Created by Damian Carrillo on 2/28/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "BPElement.h" 23 | 24 | @interface BPDocument : NSObject 25 | @property (strong, nonatomic, readonly) NSArray *elements; 26 | 27 | #if __has_feature(objc_subscripting) 28 | 29 | /*! 30 | \brief Convenience accessor for retrieving elements 31 | */ 32 | - (id)objectAtIndexedSubscript:(NSUInteger)idx; 33 | 34 | #endif 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /dep/libsoldout/expanded_markdown.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2009, Natacha Porté 4 | # 5 | # Permission to use, copy, modify, and distribute this software for any 6 | # purpose with or without fee is hereby granted, provided that the above 7 | # copyright notice and this permission notice appear in all copies. 8 | # 9 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | 17 | # This script is used for markdown validation: 18 | # The original Markdown.pl expand tabs into spaces, which is something 19 | # I don't want to do, and it cannot be easily fixed in the renderer, 20 | # so has to be preprocessed. expand(1) is used for that preprocessing, 21 | # feeding tab-free data into my markdown. 22 | 23 | expand -t 4 "$@" | $(dirname $0)/lace --markdown --xhtml 24 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPParser.mm: -------------------------------------------------------------------------------- 1 | // 2 | // BPParser.m 3 | // Bypass 4 | // 5 | // Created by Damian Carrillo on 2/28/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "BPParser.h" 22 | #import "BPDocumentPrivate.h" 23 | #import "parser.h" 24 | 25 | @implementation BPParser 26 | 27 | - (BPDocument *)parse:(NSString *)markdown 28 | { 29 | using namespace Bypass; 30 | 31 | const char *mstr = [markdown cStringUsingEncoding:NSUTF8StringEncoding]; 32 | 33 | Bypass::Parser parser = Bypass::Parser(); 34 | Document doc = parser.parse(mstr); 35 | BPDocument *document = [[BPDocument alloc] initWithDocument:doc]; 36 | 37 | return document; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /platform/android/functional-test/res/raw/readme.txt: -------------------------------------------------------------------------------- 1 | #Bypass 2 | 3 | #Header sizes 4 | ##Smaller header 5 | ##Even smaller header 6 | 7 | Paragraphs are obviously supported along with all the fancy text styling you could want. 8 | There is *italic*, **bold** and ***bold italic***. Even links are supported, visit the 9 | github page for Bypass [here](https://github.com/Uncodin/bypass). 10 | 11 | * Nested List 12 | * One 13 | * Two 14 | * Three 15 | * One 16 | * One 17 | * Two 18 | * Three 19 | 20 | ## Code Block Support 21 | 22 | const char* str; 23 | str = env->GetStringUTFChars(markdown, NULL); 24 | 25 | Bypass::Parser parser; 26 | Bypass::Document document = parser.parse(str); 27 | 28 | env->ReleaseStringUTFChars(markdown, str); 29 | 30 | 31 | #Quote Support 32 | > Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ullamcorper tempus neque vulputate congue. 33 | > Quisque ipsum tellus, pharetra vitae dictum sit amet, placerat vitae felis. Etiam ornare eleifend libero, 34 | > et dignissim nibh rhoncus eu. Morbi mattis nisi in velit tristique eu mollis odio molestie. 35 | > Phasellus pretium dapibus mattis. Nullam mollis nisl id enim vestibulum quis lacinia turpis pellentesque. 36 | > Integer id mi quam. Fusce sagittis cursus eros, nec convallis ligula consectetur quis. Suspendisse potenti. 37 | 38 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPMarkdownPageView.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPMarkdownPageView.h 3 | // Bypass 4 | // 5 | // Created by Damian Carrillo on 3/13/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import 23 | 24 | @class BPDocument; 25 | 26 | @protocol BPMarkdownPageViewLinkDelegate; 27 | 28 | @interface BPMarkdownPageView : UIView 29 | @property (weak, nonatomic) id linkDelegate; 30 | 31 | - (id)initWithFrame:(CGRect)frame textFrame:(CTFrameRef)textFrame; 32 | 33 | @end 34 | 35 | @protocol BPMarkdownPageViewLinkDelegate 36 | @required 37 | 38 | - (void)markdownPageView:(BPMarkdownPageView *)markdownPageView 39 | didHaveLinkTapped:(NSString *)link; 40 | 41 | @end -------------------------------------------------------------------------------- /dep/libsoldout/CHANGES: -------------------------------------------------------------------------------- 1 | This is the changelog for libsoldout project. 2 | Please note that this is a user-centered condensed changelog; for an 3 | exhaustive list of changes, please consult the repository, I don't see the 4 | point of duplicating this information here, while on the other hand I have 5 | often missed a simple change list containing only what affect users of 6 | release versions. 7 | 8 | 9 | ## Changes from v1.2 to 1.3 ## 10 | 11 | * New example renderer that outputs LaTeX. 12 | 13 | 14 | ## Changes from v1.1 to v1.2 ## 15 | 16 | * Name change to libsoldout 17 | 18 | * Bug fixes: 19 | + various issues with matching emphasis delimiter have been fixed 20 | + better compatibility with non-gcc compilers 21 | + GNU make now uses correct compiler options to generate PIC code 22 | 23 | 24 | ## Changes from v1.0 to v1.1 ## 25 | 26 | * New features: 27 | + new callbacks for document prolog and epilog, 28 | + support of PHP-Markdown-like tables, through 3 new callbacks. 29 | 30 | * Several bug fixes, most notably: 31 | + span-level entities are now correctly recognized in headers, 32 | + empty ATX-styles header (i.e. lines containing only '#' charcters) 33 | no longer crash the library 34 | + empty documents are now correctly handled 35 | + blackslash escapes work in inline URIs, thereby allowing to include 36 | ')' characters in such URIs. 37 | -------------------------------------------------------------------------------- /platform/android/library/src/in/uncod/android/bypass/style/HorizontalLineSpan.java: -------------------------------------------------------------------------------- 1 | package in.uncod.android.bypass.style; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Paint; 5 | import android.text.style.ReplacementSpan; 6 | 7 | /** 8 | * Draws a line across the screen. 9 | */ 10 | public class HorizontalLineSpan extends ReplacementSpan { 11 | 12 | private Paint mPaint; 13 | private int mLineHeight; 14 | private int mTopBottomPadding; 15 | 16 | public HorizontalLineSpan(int color, int lineHeight, int topBottomPadding) { 17 | mPaint = new Paint(); 18 | mPaint.setColor(color); 19 | mLineHeight = lineHeight; 20 | mTopBottomPadding = topBottomPadding; 21 | } 22 | 23 | @Override 24 | public int getSize( 25 | Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { 26 | if (fm != null) { 27 | fm.ascent = -mLineHeight - mTopBottomPadding; 28 | fm.descent = 0; 29 | 30 | fm.top = fm.ascent; 31 | fm.bottom = 0; 32 | } 33 | 34 | // Take up *all* the horizontal space 35 | return Integer.MAX_VALUE; 36 | } 37 | 38 | @Override 39 | public void draw( 40 | Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { 41 | int middle = (top + bottom) / 2; 42 | int halfLineHeight = mLineHeight / 2; 43 | canvas.drawRect(x, middle - halfLineHeight, Integer.MAX_VALUE, middle + halfLineHeight, mPaint); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPAttributedStringConverter.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPAttributedStringRenderer.h 3 | // Bypass 4 | // 5 | // Created by Damian Carrillo on 3/1/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "BPDocument.h" 23 | #import "BPImageGetter.h" 24 | 25 | @class BPDisplaySettings; 26 | 27 | OBJC_EXPORT NSString *const BPLinkStyleAttributeName; 28 | 29 | /*! 30 | \brief Renders a Bypass Document to an `NSAttributedString`. 31 | */ 32 | @interface BPAttributedStringConverter : NSObject 33 | 34 | @property(nonatomic, strong) BPDisplaySettings *displaySettings; 35 | 36 | - (NSAttributedString *)convertDocument:(BPDocument *)document; 37 | 38 | - (NSAttributedString *)convertDocument:(BPDocument *)document WithImageGetter: (id)imageGetter; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /platform/android/library/src/in/uncod/android/bypass/ReverseSpannableStringBuilder.java: -------------------------------------------------------------------------------- 1 | package in.uncod.android.bypass; 2 | 3 | import android.text.SpannableStringBuilder; 4 | 5 | /** 6 | * Exactly the same as SpannableStringBuilder, but it returns its spans in reverse. 7 | * 8 | * What effect does this have? Well, if you're building up a Spannable recursively (as we 9 | * are doing in Bypass) then returning the spans in reverse order has the correct effect 10 | * in some corner cases regarding leading spans. 11 | * 12 | * Example: 13 | * Suppose we have a BLOCK_QUOTE with a LIST inside of it. Both of them have leading spans, but the LIST 14 | * span is set first. As a result, the QuoteSpan for the BLOCK_QUOTE is actually indented by the LIST's span! 15 | * If the order is reversed, then the LIST's margin span is properly indented (and the BlockQuote remains on 16 | * the side). 17 | */ 18 | public class ReverseSpannableStringBuilder extends SpannableStringBuilder { 19 | 20 | @Override 21 | public T[] getSpans(int queryStart, int queryEnd, Class kind) { 22 | T[] ret = super.getSpans(queryStart, queryEnd, kind); 23 | reverse(ret); 24 | return ret; 25 | } 26 | 27 | private static void reverse(Object[] arr) { 28 | if (arr == null) { 29 | return; 30 | } 31 | 32 | int i = 0; 33 | int j = arr.length - 1; 34 | Object tmp; 35 | while (j > i) { 36 | tmp = arr[j]; 37 | arr[j] = arr[i]; 38 | arr[i] = tmp; 39 | j--; 40 | i++; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /platform/ios/Bypass/BypassTests/BPParserTests.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "BPParser.h" 3 | 4 | @interface BPParserTests : SenTestCase 5 | @end 6 | 7 | @implementation BPParserTests 8 | { 9 | BPParser *parser; 10 | } 11 | 12 | - (void)setUp 13 | { 14 | parser = [[BPParser alloc] init]; 15 | } 16 | 17 | - (void)testSimpleCase 18 | { 19 | NSString *example = 20 | 21 | @"This is a normal paragraph:\n" 22 | "\n" 23 | " This is a code block."; 24 | 25 | BPDocument *document = [parser parse:example]; 26 | 27 | STAssertNotNil(document, @"Expected a non-nil document"); 28 | STAssertEquals([[document elements] count], 2U, @"Expected 2 elements in document"); 29 | 30 | STAssertEquals([[document elements][0] elementType], BPParagraph, @"Expected first element to be a paragraph"); 31 | STAssertEquals([[[document elements][0] childElements][0] elementType], BPText, @"Expected first element to have an inner text element"); 32 | STAssertEqualObjects([[[document elements][0] childElements][0] text], @"This is a normal paragraph:", @"Expected first inner text element to match"); 33 | 34 | STAssertEquals([[document elements][1] elementType], BPBlockCode, @"Expected second element to be a code block"); 35 | STAssertEquals([[[document elements][1] childElements][0] elementType], BPText, @"Expected second element to have an inner text element"); 36 | STAssertEqualObjects([[[document elements][1] childElements][0] text], @"This is a code block.", @"Expected second inner text element to match"); 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BypassSample-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | Bypass 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIcons 12 | 13 | CFBundlePrimaryIcon 14 | 15 | CFBundleIconFiles 16 | 17 | iPhone Retina.png 18 | iPhone.png 19 | 20 | 21 | 22 | CFBundleIdentifier 23 | com.uncodin.${PRODUCT_NAME:rfc1034identifier} 24 | CFBundleInfoDictionaryVersion 25 | 6.0 26 | CFBundleName 27 | ${PRODUCT_NAME} 28 | CFBundlePackageType 29 | APPL 30 | CFBundleShortVersionString 31 | 1.0 32 | CFBundleSignature 33 | ???? 34 | CFBundleVersion 35 | 1.0 36 | LSRequiresIPhoneOS 37 | 38 | UIMainStoryboardFile 39 | MainStoryboard 40 | UIRequiredDeviceCapabilities 41 | 42 | armv7 43 | 44 | UISupportedInterfaceOrientations 45 | 46 | UIInterfaceOrientationPortrait 47 | UIInterfaceOrientationLandscapeLeft 48 | UIInterfaceOrientationLandscapeRight 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /platform/android/functional-test/src/in/uncod/android/bypass/test/BenchmarkActivity.java: -------------------------------------------------------------------------------- 1 | package in.uncod.android.bypass.test; 2 | 3 | import java.io.InputStream; 4 | 5 | import in.uncod.android.bypass.Bypass; 6 | import in.uncod.andrpod.bypass.bypass_test.R; 7 | import android.app.Activity; 8 | import android.content.res.Resources; 9 | import android.os.Bundle; 10 | import android.text.method.LinkMovementMethod; 11 | import android.util.TimingLogger; 12 | import android.widget.TextView; 13 | 14 | public class BenchmarkActivity extends Activity { 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | 20 | setContentView(R.layout.main); 21 | 22 | TextView text = (TextView) findViewById(R.id.demoText); 23 | 24 | TimingLogger timings = new TimingLogger("Bypass", "onCreate"); 25 | 26 | String readme = loadFile(); 27 | 28 | timings.addSplit("read raw"); 29 | 30 | Bypass bypass = new Bypass(); 31 | 32 | timings.addSplit("instantiated Bypass"); 33 | 34 | CharSequence string = bypass.markdownToSpannable(readme); 35 | 36 | timings.addSplit("convert to spannable"); 37 | timings.dumpToLog(); 38 | 39 | text.setText(string); 40 | //Allows link clicking 41 | text.setMovementMethod(LinkMovementMethod.getInstance()); 42 | } 43 | 44 | private String loadFile() { 45 | try { 46 | Resources res = getResources(); 47 | InputStream in_s = res.openRawResource(R.raw.readme); 48 | 49 | byte[] b = new byte[in_s.available()]; 50 | in_s.read(b); 51 | return new String(b); 52 | } catch (Exception e) { 53 | // e.printStackTrace(); 54 | } 55 | return ""; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /platform/ios/Bypass/BypassTests/BPDocumentTests.mm: -------------------------------------------------------------------------------- 1 | #import 2 | #import "BPDocumentPrivate.h" 3 | 4 | @interface BPDocumentTests : SenTestCase 5 | @end 6 | 7 | @implementation BPDocumentTests 8 | { 9 | BPDocument *document; 10 | } 11 | 12 | - (void)setUp 13 | { 14 | using namespace Bypass; 15 | 16 | Document d; 17 | 18 | Element e0; 19 | e0.setType(PARAGRAPH); 20 | e0.setText("text"); 21 | e0.addAttribute("a", "A"); 22 | e0.addAttribute("b", "B"); 23 | d.append(e0); 24 | 25 | Element e1; 26 | e1.setType(PARAGRAPH); 27 | e1.setText("text"); 28 | e1.addAttribute("a", "A"); 29 | e1.addAttribute("b", "B"); 30 | d.append(e1); 31 | 32 | document = [[BPDocument alloc] initWithDocument:d]; 33 | } 34 | 35 | - (void)testInitialization 36 | { 37 | STAssertNotNil(document, @"Expected non-nil document"); 38 | } 39 | 40 | - (void)testElementsAccessor_forPointerEquality 41 | { 42 | NSArray *elements = [document elements]; 43 | STAssertEquals([document elements], elements, @"Expected same elements"); 44 | } 45 | 46 | - (void)testChildElements 47 | { 48 | STAssertEquals([[document elements] count], 2U, @"Expected 2 elements"); 49 | STAssertEquals([[document elements][0] elementType], BPParagraph, @"Expected first element type to be BPParagraph"); 50 | STAssertEquals([[document elements][1] elementType], BPParagraph, @"Expected second element type to be BPParagraph"); 51 | } 52 | 53 | #if __has_feature(objc_subscripting) 54 | 55 | - (void)testNumericSubscripting 56 | { 57 | STAssertEquals(document[0], [[document elements] objectAtIndex:0], @"Expected document subscripting to return an element"); 58 | } 59 | 60 | #endif 61 | 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Bypass 2 | ====== 3 | 4 | Skip the HTML, Bypass takes markdown and renders it directly on Android and iOS. 5 | 6 | ## License 7 | 8 | [Apache License v2.0](http://www.tldrlegal.com/l/APACHE2) 9 | 10 | ## Requirements 11 | 12 | - Boost must be [installed on your system](http://www.boost.org/doc/libs/1_53_0/more/getting_started/index.html) 13 | 14 | ## Android 15 | 16 | If you just want to include Bypass in your Maven project, add the following 17 | dependency block to your `pom.xml`: 18 | 19 | 20 | in.uncod.android.bypass 21 | bypass 22 | apklib 23 | 1.1 24 | 25 | 26 | [Building And Using](platform/android/README.md) 27 | 28 | ### Contributors 29 | 30 | * [Colin Edwards](https://github.com/DDRBoxman) 31 | * [Cameron Currie](https://github.com/cwc) 32 | * [Albert Wang](https://github.com/albert-wang) 33 | * [Jimi Smith](https://github.com/JimiSmith) 34 | * [Dan Lew](https://github.com/dlew) 35 | 36 | ## iOS 37 | 38 | [Building And Using](platform/ios/README.md) 39 | 40 | ### Contributors 41 | 42 | * [Damian Carrillo](https://github.com/damiancarrillo) 43 | * [Cameron Currie](https://github.com/cwc) 44 | * [Albert Wang](https://github.com/albert-wang) 45 | * [Matthias Tretter](https://github.com/myell0w) 46 | * [Audun Holm Ellertsen](https://github.com/audun) 47 | * [Vinh Nguyen](https://github.com/vinhnx) 48 | * [Victor L. Oliveira](https://github.com/victorlaerte) 49 | 50 | ## 3rd Party Libraries 51 | 52 | - [**Boost**](http://www.boost.org/) - [license](http://www.boost.org/LICENSE_1_0.txt) 53 | - [**libsoldout**](http://fossil.instinctive.eu/libsoldout/home) - [license](http://fossil.instinctive.eu/libsoldout/artifact/c8d2f5b1e9e1df422ca06d1bc846d9e3055a925b) 54 | -------------------------------------------------------------------------------- /platform/android/functional-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | in.uncod.android.bypass 5 | functional-test 6 | apk 7 | Functional Test 8 | 9 | 10 | in.uncod.android.bypass 11 | parent 12 | 1.2-SNAPSHOT 13 | ../pom.xml 14 | 15 | 16 | 17 | 18 | com.google.android 19 | android 20 | provided 21 | 22 | 23 | in.uncod.android.bypass 24 | bypass 25 | apklib 26 | 1.2-SNAPSHOT 27 | 28 | 29 | 30 | 31 | src 32 | 33 | 34 | org.apache.maven.plugins 35 | maven-compiler-plugin 36 | 37 | 1.6 38 | 1.6 39 | 40 | 41 | 42 | com.jayway.maven.plugins.android.generation2 43 | android-maven-plugin 44 | 45 | 46 | ${env.ANDROID_HOME} 47 | 16 48 | 49 | 50 | true 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPDisplaySettings.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Audun Holm Ellertsen on 4/30/13. 3 | // Copyright (c) 2013 Uncodin. All rights reserved. 4 | // 5 | // To change the template use AppCode | Preferences | File Templates. 6 | // 7 | 8 | 9 | #import 10 | #import 11 | 12 | @interface BPDisplaySettings : NSObject 13 | 14 | @property(nonatomic) UIColor *defaultColor; 15 | @property(nonatomic) UIColor *quoteColor; 16 | @property(nonatomic) UIColor *codeColor; 17 | @property(nonatomic) UIColor *linkColor; 18 | 19 | @property(nonatomic) UIFont *defaultFont; 20 | @property(nonatomic) UIFont *boldFont; 21 | @property(nonatomic) UIFont *italicFont; 22 | @property(nonatomic) UIFont *boldItalicFont; 23 | @property(nonatomic) UIFont *monospaceFont; 24 | @property(nonatomic) UIFont *quoteFont; 25 | @property(nonatomic) UIFont *h1Font; 26 | @property(nonatomic) UIFont *h2Font; 27 | @property(nonatomic) UIFont *h3Font; 28 | @property(nonatomic) UIFont *h4Font; 29 | @property(nonatomic) UIFont *h5Font; 30 | @property(nonatomic) UIFont *h6Font; 31 | 32 | @property(nonatomic) CGFloat bulletIndentation; 33 | @property(nonatomic) CGFloat codeIndentation; 34 | @property(nonatomic) CGFloat quoteIndentation; 35 | @property(nonatomic) CGFloat lineSpacingSmall; 36 | 37 | @property(nonatomic) CGFloat paragraphSpacing; 38 | @property(nonatomic) CGFloat paragraphSpacingHeading; 39 | @property(nonatomic) CGFloat paragraphSpacingH2; 40 | 41 | @property(nonatomic) CGFloat paragraphSpacingCode; 42 | 43 | @property(nonatomic) CGFloat paragraphLineSpacing; 44 | @property(nonatomic) CGFloat paragraphLineSpacingHeading; 45 | 46 | @property(nonatomic) CGFloat firstParagraphFirstLineHeadIndent; 47 | 48 | @property(nonatomic) CGFloat paragraphFirstLineHeadIndent; 49 | @property(nonatomic) CGFloat paragraphHeadIndent; 50 | 51 | @property(nonatomic) CGFloat headerFirstLineHeadIndent; 52 | @property(nonatomic) CGFloat headerHeadIndent; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /platform/android/functional-test-tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | in.uncod.android.bypass 6 | functional-test-tests 7 | apk 8 | Functional Test Tests 9 | 10 | 11 | in.uncod.android.bypass 12 | parent 13 | 1.2-SNAPSHOT 14 | ../pom.xml 15 | 16 | 17 | 18 | 19 | com.google.android 20 | android 21 | provided 22 | 23 | 24 | com.google.android 25 | android-test 26 | provided 27 | 28 | 29 | in.uncod.android.bypass 30 | functional-test 31 | 1.2-SNAPSHOT 32 | apk 33 | 34 | 35 | 36 | src 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-compiler-plugin 41 | 42 | 1.6 43 | 1.6 44 | 45 | 46 | 47 | com.jayway.maven.plugins.android.generation2 48 | android-maven-plugin 49 | 50 | 51 | ${env.ANDROID_HOME} 52 | 16 53 | 54 | 55 | true 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /dep/libsoldout/GNUmakefile: -------------------------------------------------------------------------------- 1 | # Makefile 2 | 3 | # Copyright (c) 2009, Natacha Porté 4 | # 5 | # Permission to use, copy, modify, and distribute this software for any 6 | # purpose with or without fee is hereby granted, provided that the above 7 | # copyright notice and this permission notice appear in all copies. 8 | # 9 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | 17 | DEPDIR=depends 18 | CFLAGS=-c -g -O3 -Wall -Werror -fPIC 19 | LDFLAGS=-g -O3 -Wall -Werror 20 | CC=gcc 21 | 22 | all: libsoldout.so 23 | 24 | .PHONY: all clean 25 | 26 | 27 | # libraries 28 | 29 | libsoldout.so: libsoldout.so.1 30 | ln -s $^ $@ 31 | 32 | libsoldout.so.1: markdown.o array.o buffer.o renderers.o 33 | $(CC) $(LDFLAGS) -shared -Wl $^ -o $@ 34 | 35 | 36 | # executables 37 | 38 | mkd2html: mkd2html.o libsoldout.so 39 | $(CC) $(LDFLAGS) $^ -o $@ 40 | 41 | mkd2latex: mkd2latex.o libsoldout.so 42 | $(CC) $(LDFLAGS) $^ -o $@ 43 | 44 | mkd2man: mkd2man.o libsoldout.so 45 | $(CC) $(LDFLAGS) $^ -o $@ 46 | 47 | 48 | # housekeeping 49 | 50 | benchmark: benchmark.o libsoldout.so 51 | $(CC) $(LDFLAGS) $^ -o $@ 52 | 53 | clean: 54 | rm -f *.o 55 | rm -f libsoldout.so libsoldout.so.* 56 | rm -f mkd2html mkd2latex mkd2man benchmark 57 | rm -rf $(DEPDIR) 58 | 59 | 60 | # dependencies 61 | 62 | include $(wildcard $(DEPDIR)/*.d) 63 | 64 | 65 | # generic object compilations 66 | 67 | %.o: %.c 68 | @mkdir -p $(DEPDIR) 69 | @$(CC) -MM $< > $(DEPDIR)/$*.d 70 | $(CC) $(CFLAGS) -o $@ $< 71 | 72 | %.o: %.m 73 | @mkdir -p $(DEPDIR) 74 | @$(CC) -MM $< > depends/$*.d 75 | $(CC) $(CFLAGS) -o $@ $< 76 | -------------------------------------------------------------------------------- /dep/libsoldout/renderers.h: -------------------------------------------------------------------------------- 1 | /* renderers.h - example markdown renderers */ 2 | 3 | /* 4 | * Copyright (c) 2009, Natacha Porté 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef MARKDOWN_RENDERERS_H 20 | #define MARKDOWN_RENDERERS_H 21 | 22 | #include "markdown.h" 23 | 24 | 25 | /***************************** 26 | * EXPORTED HELPER FUNCTIONS * 27 | *****************************/ 28 | 29 | /* lus_attr_escape • copy the buffer entity-escaping '<', '>', '&' and '"' */ 30 | void 31 | lus_attr_escape(struct buf *ob, char *src, size_t size); 32 | 33 | /* lus_body_escape • copy the buffer entity-escaping '<', '>' and '&' */ 34 | void 35 | lus_body_escape(struct buf *ob, char *src, size_t size); 36 | 37 | 38 | 39 | /*********************** 40 | * RENDERER STRUCTURES * 41 | ***********************/ 42 | 43 | /* original markdown renderers */ 44 | extern const struct mkd_renderer mkd_html; /* HTML 4 renderer */ 45 | extern const struct mkd_renderer mkd_xhtml; /* XHTML 1.0 renderer */ 46 | 47 | /* renderers with some discount extensions */ 48 | extern const struct mkd_renderer discount_html; 49 | extern const struct mkd_renderer discount_xhtml; 50 | 51 | /* renderers with Natasha's own extensions */ 52 | extern const struct mkd_renderer nat_html; 53 | extern const struct mkd_renderer nat_xhtml; 54 | 55 | #endif /* ndef MARKDOWN_RENDERERS_H */ 56 | -------------------------------------------------------------------------------- /platform/android/library/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | in.uncod.android.bypass 6 | bypass 7 | apklib 8 | Bypass 9 | 10 | 11 | in.uncod.android.bypass 12 | parent 13 | 1.2-SNAPSHOT 14 | ../pom.xml 15 | 16 | 17 | 18 | 19 | com.google.android 20 | android 21 | provided 22 | 23 | 24 | 25 | 26 | src 27 | 28 | 29 | 30 | com.jayway.maven.plugins.android.generation2 31 | android-maven-plugin 32 | 33 | 35 | 36 | 37 | ndk-build 38 | 39 | 40 | all 41 | true 42 | 44 | true 45 | 48 | true 49 | 50 | 51 | 52 | true 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /platform/android/README.md: -------------------------------------------------------------------------------- 1 | ### Usage 2 | 3 | TextView text = (TextView) findViewById(R.id.demoText); 4 | Bypass bypass = new Bypass(); 5 | String markdownString = "#Markdown!"; 6 | CharSequence string = bypass.markdownToSpannable(markdownString); 7 | text.setText(string); 8 | text.setMovementMethod(LinkMovementMethod.getInstance()); 9 | 10 | ### Maven Dependency 11 | If you just want to include Bypass in your Maven project, add the following 12 | dependency block to your `pom.xml`: 13 | 14 | 15 | in.uncod.android.bypass 16 | bypass 17 | apklib 18 | 1.1 19 | 20 | 21 | ### Manual Build 22 | Make sure `$ANDROID_NDK_HOME` is correctly set to the root directory of your 23 | NDK installation. Also, if Boost lives in a non-standard directory (or you're 24 | on Windows) you'll need to set `$BYPASS_INCLUDE_PATH` to its parent directory. 25 | 26 | #### Maven 27 | cd ./platform/android 28 | mvn install 29 | 30 | #### Library Project 31 | cd ./platform/android/library 32 | ndk-build 33 | 34 | Then simply point to the library from your project. 35 | 36 | ## Speed 37 | 38 | ### Android 39 | The following benchmarks were obtained by clocking the parsing of Sundown's readme file. 40 | 41 | ##### Bypass 42 | 03-01 15:13:12.662: D/Bypass(8998): onCreate: begin 43 | 03-01 15:13:12.662: D/Bypass(8998): onCreate: 1 ms, read raw 44 | 03-01 15:13:12.662: D/Bypass(8998): onCreate: 2 ms, instantiated Bypass 45 | 03-01 15:13:12.662: D/Bypass(8998): onCreate: 37 ms, convert to spannable 46 | 03-01 15:13:12.662: D/Bypass(8998): onCreate: end, 40 ms 47 | 48 | ##### [cwac-anddown](https://github.com/commonsguy/cwac-anddown) 49 | 03-01 15:14:44.662: D/AndDown(9047): onCreate: begin 50 | 03-01 15:14:44.662: D/AndDown(9047): onCreate: 2 ms, read raw 51 | 03-01 15:14:44.662: D/AndDown(9047): onCreate: 2 ms, instantiated AndDown 52 | 03-01 15:14:44.662: D/AndDown(9047): onCreate: 2 ms, convert to HTML 53 | 03-01 15:14:44.662: D/AndDown(9047): onCreate: 167 ms, convert to Spanned 54 | 03-01 15:14:44.662: D/AndDown(9047): onCreate: end, 173 ms 55 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPMarkdownView.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPMarkdownView.h 3 | // Bypass 4 | // 5 | // Created by Damian Carrillo on 3/20/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | 23 | @protocol BPMarkdownViewLinkDelegate; 24 | @class BPDisplaySettings; 25 | 26 | @interface BPMarkdownView : UIScrollView 27 | 28 | /*! 29 | * The markdown that this view will show. 30 | */ 31 | @property (strong, nonatomic) NSString *markdown; 32 | 33 | @property (strong, nonatomic) BPDisplaySettings *displaySettings; 34 | 35 | /*! 36 | * Whether or not to render the markdown asynchronously. If you are concerned with loading long 37 | * bodies of text, this may be of use to you. You can schedule the view to immediately load, 38 | * render markdown to Core Text frames in the background, and then show the results when it 39 | * has finished. 40 | * 41 | * The default is to load synchronously. 42 | */ 43 | @property (assign, nonatomic, getter = isAsynchronous) BOOL asynchronous; 44 | 45 | /*! 46 | * The duration at which an asynchronous load operation will fade the text in at. This property 47 | * only has an effect when this view loads asynchronously. 48 | */ 49 | @property (assign, nonatomic) NSTimeInterval asynchronousRevealDuration; 50 | 51 | /*! 52 | * The delegate that should handle link taps. By default this view will use the system to open 53 | * links based on whatever handler is most appropriate. 54 | */ 55 | @property (weak, nonatomic) id linkDelegate; 56 | 57 | - (id)initWithFrame:(CGRect)frame markdown:(NSString *)markdown; 58 | 59 | @end 60 | 61 | @protocol BPMarkdownViewLinkDelegate 62 | 63 | - (void)markdownView:(BPMarkdownView *)markdownView didHaveLinkTapped:(NSString *)link; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /test/document_tests.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2013 Uncodin, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #define BOOST_TEST_MODULE DocumentTests 18 | 19 | #include 20 | #include 21 | #include 22 | #include "document.h" 23 | 24 | using namespace Bypass; 25 | 26 | struct F { 27 | F() 28 | : document() 29 | { 30 | 31 | } 32 | 33 | ~F() { 34 | 35 | } 36 | 37 | Document document; 38 | }; 39 | 40 | BOOST_FIXTURE_TEST_CASE(document_initial_size, F) { 41 | BOOST_REQUIRE(document.size() == 0); 42 | } 43 | 44 | BOOST_FIXTURE_TEST_CASE(document_append_single, F) { 45 | Element element; 46 | 47 | document.append(element); 48 | BOOST_REQUIRE(document.size() == 1); 49 | } 50 | 51 | BOOST_FIXTURE_TEST_CASE(document_append_multiple, F) { 52 | int i, count = 3; 53 | 54 | for (i = 0; i < count; i++) { 55 | Element element; 56 | char str[10]; 57 | sprintf(str, "%d", i); 58 | element.setText(std::string(str)); 59 | document.append(element); 60 | } 61 | 62 | BOOST_REQUIRE(document.size() == 3); 63 | } 64 | 65 | BOOST_FIXTURE_TEST_CASE(document_access_single, F) { 66 | std::string expected = "expected"; 67 | 68 | Element element; 69 | element.setText(expected); 70 | 71 | document.append(element); 72 | 73 | BOOST_REQUIRE(document[0].getText() == expected); 74 | } 75 | 76 | BOOST_FIXTURE_TEST_CASE(document_access_multiple, F) { 77 | int i, count = 3; 78 | 79 | for (i = 0; i < count; i++) { 80 | Element element; 81 | 82 | char str[10]; 83 | sprintf(str, "%d", i); 84 | 85 | const std::string value = std::string(str); 86 | 87 | element.setText(value); 88 | document.append(element); 89 | } 90 | 91 | BOOST_REQUIRE(document[0].getText() == "0"); 92 | BOOST_REQUIRE(document[1].getText() == "1"); 93 | BOOST_REQUIRE(document[2].getText() == "2"); 94 | } -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPDocument.mm: -------------------------------------------------------------------------------- 1 | // 2 | // BPDocument.m 3 | // Bypass 4 | // 5 | // Created by Damian Carrillo on 2/28/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "BPDocumentPrivate.h" 22 | 23 | @implementation BPDocument 24 | { 25 | Bypass::Document _document; 26 | NSArray *_elements; 27 | } 28 | 29 | - (id)init 30 | { 31 | Bypass::Document document; 32 | return [self initWithDocument:document]; 33 | } 34 | 35 | - (id)initWithDocument:(Bypass::Document)document 36 | { 37 | self = [super init]; 38 | 39 | if (self != nil) { 40 | _document = document; 41 | } 42 | 43 | return self; 44 | } 45 | 46 | - (NSArray *)elements 47 | { 48 | using namespace Bypass; 49 | 50 | if (_elements == nil) { 51 | size_t i, count = _document.size(); 52 | 53 | NSMutableArray *elements = [NSMutableArray arrayWithCapacity:count]; 54 | 55 | for (i = 0; i < count; ++i) { 56 | Element e = _document[i]; 57 | 58 | BPElement *ee = [[BPElement alloc] initWithElement:e]; 59 | elements[i] = ee; 60 | } 61 | 62 | _elements = [NSArray arrayWithArray:elements]; 63 | } 64 | 65 | return _elements; 66 | } 67 | 68 | #if __has_feature(objc_subscripting) 69 | 70 | - (id)objectAtIndexedSubscript:(NSUInteger)idx 71 | { 72 | return [[self elements] objectAtIndexedSubscript:idx]; 73 | } 74 | 75 | #endif 76 | 77 | - (NSString *)debugDescription 78 | { 79 | NSMutableString *desc = [NSMutableString stringWithString:NSStringFromClass([self class])]; 80 | [desc appendString:@"{ childElements:"]; 81 | 82 | for (BPElement *element in [self elements]) { 83 | [desc appendFormat:@"%@\n", [element debugDescription]]; 84 | } 85 | 86 | [desc appendString:@"}"]; 87 | return desc; 88 | } 89 | 90 | 91 | @end 92 | -------------------------------------------------------------------------------- /dep/libsoldout/BSDmakefile: -------------------------------------------------------------------------------- 1 | # Makefile 2 | 3 | # Copyright (c) 2009, Natacha Porté 4 | # 5 | # Permission to use, copy, modify, and distribute this software for any 6 | # purpose with or without fee is hereby granted, provided that the above 7 | # copyright notice and this permission notice appear in all copies. 8 | # 9 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | 17 | DEPDIR=depends 18 | ALLDEPS=$(DEPDIR)/all 19 | CFLAGS=-c -g -O3 -Wall -Werror -fPIC 20 | LDFLAGS=-g -O3 -Wall -Werror 21 | CC=gcc 22 | 23 | all: libsoldout.so mkd2html mkd2latex mkd2man 24 | 25 | .PHONY: all clean 26 | 27 | 28 | # libraries 29 | 30 | libsoldout.so: libsoldout.so.1 31 | ln -s $(.ALLSRC) $(.TARGET) 32 | 33 | libsoldout.so.1: markdown.o array.o buffer.o renderers.o 34 | $(CC) $(LDFLAGS) -shared -Wl,-soname=$(.TARGET) \ 35 | $(.ALLSRC) -o $(.TARGET) 36 | 37 | 38 | # executables 39 | 40 | mkd2html: mkd2html.o libsoldout.so 41 | $(CC) $(LDFLAGS) $(.ALLSRC) -o $(.TARGET) 42 | 43 | mkd2latex: mkd2latex.o libsoldout.so 44 | $(CC) $(LDFLAGS) $(.ALLSRC) -o $(.TARGET) 45 | 46 | mkd2man: mkd2man.o libsoldout.so 47 | $(CC) $(LDFLAGS) $(.ALLSRC) -o $(.TARGET) 48 | 49 | 50 | # Housekeeping 51 | 52 | benchmark: benchmark.o libsoldout.so 53 | $(CC) $(LDFLAGS) $(.ALLSRC) -o $(.TARGET) 54 | 55 | clean: 56 | rm -f *.o 57 | rm -f libsoldout.so libsoldout.so.* 58 | rm -f mkd2html mkd2latex mkd2man benchmark 59 | rm -rf $(DEPDIR) 60 | 61 | 62 | # dependencies 63 | 64 | .sinclude "$(ALLDEPS)" 65 | 66 | 67 | # generic object compilations 68 | 69 | .c.o: 70 | @mkdir -p $(DEPDIR) 71 | @touch $(ALLDEPS) 72 | @$(CC) -MM $(.IMPSRC) > $(DEPDIR)/$(.PREFIX).d 73 | @grep -q "$(.PREFIX).d" $(ALLDEPS) \ 74 | || echo ".include \"$(.PREFIX).d\"" >> $(ALLDEPS) 75 | $(CC) $(CFLAGS) -o $(.TARGET) $(.IMPSRC) 76 | 77 | .m.o: 78 | @mkdir -p $(DEPDIR) 79 | @touch $(ALLDEPS) 80 | @$(CC) -MM $(.IMPSRC) > depends/$(.PREFIX).d 81 | @grep -q "$(.PREFIX).d" $(ALLDEPS) \ 82 | || echo ".include \"$(.PREFIX).d\"" >> $(ALLDEPS) 83 | $(CC) $(CFLAGS) -o $(.TARGET) $(.IMPSRC) 84 | -------------------------------------------------------------------------------- /platform/android/library/src/in/uncod/android/bypass/Element.java: -------------------------------------------------------------------------------- 1 | package in.uncod.android.bypass; 2 | 3 | import java.util.Map; 4 | import java.util.HashMap; 5 | 6 | public class Element { 7 | 8 | public static final int F_LIST_ORDERED = 1; 9 | 10 | public enum Type { 11 | 12 | // Block Element Types 13 | 14 | BLOCK_CODE(0x000), 15 | BLOCK_QUOTE(0x001), 16 | BLOCK_HTML(0x002), 17 | HEADER(0x003), 18 | HRULE(0x004), 19 | LIST(0x005), 20 | LIST_ITEM(0x006), 21 | PARAGRAPH(0x007), 22 | TABLE(0x008), 23 | TABLE_CELL(0x009), 24 | TABLE_ROW(0x00A), 25 | 26 | // Span Element Types 27 | 28 | AUTOLINK(0x10B), 29 | CODE_SPAN(0x10C), 30 | DOUBLE_EMPHASIS(0x10D), 31 | EMPHASIS(0x10E), 32 | IMAGE(0x10F), 33 | LINEBREAK(0x110), 34 | LINK(0x111), 35 | RAW_HTML_TAG(0x112), 36 | TRIPLE_EMPHASIS(0x113), 37 | TEXT(0x114), 38 | STRIKETHROUGH(0x115); 39 | 40 | private final int value; 41 | 42 | private Type(int value) { 43 | this.value = value; 44 | } 45 | 46 | private static final Type[] TypeValues = Type.values(); 47 | public static Type fromInteger(int x) { 48 | for (Type type : TypeValues) { 49 | if (type.value == x) { 50 | return type; 51 | } 52 | } 53 | return null; 54 | } 55 | } 56 | 57 | String text; 58 | Map attributes = new HashMap(); 59 | Element[] children; 60 | Type type; 61 | Element parent; 62 | int nestLevel = 0; 63 | 64 | public Element(String text, int type) { 65 | this.text = text; 66 | this.type = Type.fromInteger(type); 67 | } 68 | 69 | public void setParent(Element element) { 70 | this.parent = element; 71 | } 72 | 73 | public void setChildren(Element[] children) { 74 | this.children = children; 75 | } 76 | 77 | public void addAttribute(String name, String value) { 78 | attributes.put(name, value); 79 | } 80 | 81 | public String getAttribute(String name) { 82 | return attributes.get(name); 83 | } 84 | 85 | public Element getParent() { 86 | return parent; 87 | } 88 | 89 | public String getText() { 90 | return text; 91 | } 92 | 93 | public int size() { 94 | if (children != null) { 95 | return children.length; 96 | } 97 | return 0; 98 | } 99 | 100 | public Type getType() { 101 | return type; 102 | } 103 | 104 | public boolean isBlockElement() { 105 | return (type.value & 0x100) == 0x000; 106 | } 107 | 108 | public boolean isSpanElement() { 109 | return (type.value & 0x100) == 0x100; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/element.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2013 Uncodin, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef BYPASS_ELEMENT_H 18 | #define BYPASS_ELEMENT_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "element.h" 26 | 27 | namespace Bypass { 28 | 29 | enum Type { 30 | 31 | // Block Element Types 32 | 33 | BLOCK_CODE = 0x000, 34 | BLOCK_QUOTE = 0x001, 35 | BLOCK_HTML = 0x002, 36 | HEADER = 0x003, 37 | HRULE = 0x004, 38 | LIST = 0x005, 39 | LIST_ITEM = 0x006, 40 | PARAGRAPH = 0x007, 41 | TABLE = 0x008, 42 | TABLE_CELL = 0x009, 43 | TABLE_ROW = 0x00A, 44 | 45 | // Span Element Types 46 | 47 | AUTOLINK = 0x10B, 48 | CODE_SPAN = 0x10C, 49 | DOUBLE_EMPHASIS = 0x10D, 50 | EMPHASIS = 0x10E, 51 | IMAGE = 0x10F, 52 | LINEBREAK = 0x110, 53 | LINK = 0x111, 54 | RAW_HTML_TAG = 0x112, 55 | TRIPLE_EMPHASIS = 0x113, 56 | TEXT = 0x114, 57 | STRIKETHROUGH = 0x115 58 | }; 59 | 60 | class Element { 61 | public: 62 | typedef std::map AttributeMap; 63 | 64 | Element(); 65 | ~Element(); 66 | 67 | std::string text; 68 | 69 | void setText(const std::string& text); 70 | const std::string& getText(); 71 | 72 | void addAttribute(const std::string& name, const std::string& value); 73 | std::string getAttribute(const std::string& name); 74 | 75 | AttributeMap::iterator attrBegin(); 76 | AttributeMap::iterator attrEnd(); 77 | size_t attrSize() const; 78 | 79 | void append(const Element& blockElement); 80 | Element getChild(size_t i); 81 | Element operator[](size_t i); 82 | void setType(Type type); 83 | Type getType(); 84 | bool isBlockElement(); 85 | bool isSpanElement(); 86 | size_t size(); 87 | friend std::ostream& operator<<(std::ostream& out, const Element& element); 88 | private: 89 | AttributeMap attributes; 90 | std::vector children; 91 | Type type; 92 | }; 93 | 94 | } 95 | 96 | #endif // BYPASS_ELEMENT_H 97 | -------------------------------------------------------------------------------- /logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | iPhone Retina 4 | Created with Sketch (http://www.bohemiancoding.com/sketch) 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 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BPAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // BPAppDelegate.m 3 | // BypassSample 4 | // 5 | // Created by Damian Carrillo on 3/1/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "BPAppDelegate.h" 22 | 23 | @implementation BPAppDelegate 24 | 25 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 26 | { 27 | // Override point for customization after application launch. 28 | return YES; 29 | } 30 | 31 | - (void)applicationWillResignActive:(UIApplication *)application 32 | { 33 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 34 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 35 | } 36 | 37 | - (void)applicationDidEnterBackground:(UIApplication *)application 38 | { 39 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 40 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 41 | } 42 | 43 | - (void)applicationWillEnterForeground:(UIApplication *)application 44 | { 45 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 46 | } 47 | 48 | - (void)applicationDidBecomeActive:(UIApplication *)application 49 | { 50 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 51 | } 52 | 53 | - (void)applicationWillTerminate:(UIApplication *)application 54 | { 55 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 56 | } 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPElement.h: -------------------------------------------------------------------------------- 1 | // 2 | // BPElement.h 3 | // Bypass 4 | // 5 | // Created by Damian Carrillo on 2/28/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | 23 | typedef NSUInteger BPElementType; 24 | 25 | // Block Element Types 26 | 27 | FOUNDATION_EXPORT const BPElementType BPBlockCode; 28 | FOUNDATION_EXPORT const BPElementType BPBlockQuote; 29 | FOUNDATION_EXPORT const BPElementType BPBlockHTML; 30 | FOUNDATION_EXPORT const BPElementType BPHeader; 31 | FOUNDATION_EXPORT const BPElementType BPHRule; 32 | FOUNDATION_EXPORT const BPElementType BPList; 33 | FOUNDATION_EXPORT const BPElementType BPListItem; 34 | FOUNDATION_EXPORT const BPElementType BPParagraph; 35 | FOUNDATION_EXPORT const BPElementType BPTable; 36 | FOUNDATION_EXPORT const BPElementType BPTableCell; 37 | FOUNDATION_EXPORT const BPElementType BPTableRow; 38 | 39 | // Span Element Types 40 | 41 | FOUNDATION_EXPORT const BPElementType BPAutoLink; 42 | FOUNDATION_EXPORT const BPElementType BPCodeSpan; 43 | FOUNDATION_EXPORT const BPElementType BPDoubleEmphasis; 44 | FOUNDATION_EXPORT const BPElementType BPEmphasis; 45 | FOUNDATION_EXPORT const BPElementType BPImage; 46 | FOUNDATION_EXPORT const BPElementType BPLineBreak; 47 | FOUNDATION_EXPORT const BPElementType BPLink; 48 | FOUNDATION_EXPORT const BPElementType BPRawHTMLTag; 49 | FOUNDATION_EXPORT const BPElementType BPTripleEmphasis; 50 | FOUNDATION_EXPORT const BPElementType BPText; 51 | FOUNDATION_EXPORT const BPElementType BPStrikethrough; 52 | 53 | @interface BPElement : NSObject 54 | @property (assign, nonatomic, readonly) BPElementType elementType; 55 | @property (strong, nonatomic, readonly) NSString *text; 56 | @property (strong, nonatomic, readonly) NSDictionary *attributes; 57 | @property (weak, nonatomic, readonly) BPElement *parentElement; 58 | @property (strong, nonatomic, readonly) NSArray *childElements; 59 | 60 | - (BOOL)isBlockElement; 61 | 62 | #if __has_feature(objc_subscripting) 63 | 64 | /*! 65 | \brief Convenience accessor for retrieving child elements 66 | */ 67 | - (id)objectAtIndexedSubscript:(NSUInteger)idx; 68 | 69 | /*! 70 | \brief Convenience accessor for retrieving attributes 71 | */ 72 | - (id)objectForKeyedSubscript:(id)key; 73 | 74 | #endif 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /platform/android/functional-test-tests/src/in/uncod/andrpod/bypass/bypass_test/test/BasicTests.java: -------------------------------------------------------------------------------- 1 | package in.uncod.andrpod.bypass.bypass_test.test; 2 | 3 | import in.uncod.android.bypass.Bypass; 4 | import android.graphics.Typeface; 5 | import android.test.InstrumentationTestCase; 6 | import android.text.Spannable; 7 | import android.text.SpannedString; 8 | import android.text.style.BulletSpan; 9 | import android.text.style.LeadingMarginSpan; 10 | import android.text.style.RelativeSizeSpan; 11 | import android.text.style.StyleSpan; 12 | import android.text.style.TypefaceSpan; 13 | import android.text.style.URLSpan; 14 | 15 | public class BasicTests extends InstrumentationTestCase { 16 | 17 | Bypass bypass; 18 | 19 | @Override 20 | protected void setUp() throws Exception { 21 | super.setUp(); 22 | 23 | bypass = new Bypass(); 24 | } 25 | 26 | @Override 27 | protected void tearDown() throws Exception { 28 | super.tearDown(); 29 | } 30 | 31 | public void testEmptyString() { 32 | bypass.markdownToSpannable(""); 33 | } 34 | 35 | public void testHeaderString() { 36 | Spannable spannable = (Spannable) bypass.markdownToSpannable("Header!!\n--------"); 37 | StyleSpan[] spans = spannable.getSpans(0, spannable.length(), StyleSpan.class); 38 | assertEquals(1, spans.length); 39 | RelativeSizeSpan[] sizeSpan = spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class); 40 | assertEquals(1, sizeSpan.length); 41 | assertEquals('\n', spannable.charAt(spannable.length() - 1)); 42 | } 43 | 44 | public void testBoldString() { 45 | Spannable spannable = (Spannable) bypass.markdownToSpannable("One **Two** Three"); 46 | StyleSpan[] spans = spannable.getSpans(0, spannable.length(), StyleSpan.class); 47 | assertEquals(1, spans.length); 48 | assertEquals(Typeface.BOLD, spans[0].getStyle()); 49 | assertEquals(4, spannable.getSpanStart(spans[0])); 50 | assertEquals(7, spannable.getSpanEnd(spans[0])); 51 | } 52 | 53 | public void testLinkString() { 54 | Spannable spannable = (Spannable) bypass.markdownToSpannable("[Link](https://github.com/Uncodin/bypass)"); 55 | URLSpan[] spans = spannable.getSpans(0, spannable.length(), URLSpan.class); 56 | assertEquals(1, spans.length); 57 | assertTrue(spannable.toString().contains("Link")); 58 | assertEquals("https://github.com/Uncodin/bypass", spans[0].getURL()); 59 | } 60 | 61 | public void testHeaderOrder() { 62 | SpannedString spannable = (SpannedString) bypass.markdownToSpannable("Header!!\n--------\nText goes here or something\n*One* **Two** ***Three***\n"); 63 | RelativeSizeSpan[] sizeSpan = spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class); 64 | assertEquals(1, sizeSpan.length); 65 | assertEquals(0, spannable.getSpanStart(sizeSpan[0])); 66 | } 67 | 68 | public void testCodeSpan() { 69 | Spannable spannable = (Spannable) bypass.markdownToSpannable("`code`"); 70 | TypefaceSpan[] spans = spannable.getSpans(0, spannable.length(), TypefaceSpan.class); 71 | assertEquals(1, spans.length); 72 | assertEquals(0, spannable.getSpanStart(spans[0])); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /platform/android/library/jni/bypass.cpp: -------------------------------------------------------------------------------- 1 | #include "parser.h" 2 | #include "in_uncod_android_bypass_Bypass.h" 3 | 4 | namespace boost 5 | { 6 | void throw_exception(std::exception const&) {} 7 | } 8 | 9 | jclass java_element_class; 10 | jmethodID java_element_init; 11 | jmethodID java_element_addAttr; 12 | jmethodID java_element_setChildren; 13 | jmethodID java_element_setParent; 14 | 15 | jobject recurseElement(JNIEnv *env, Bypass::Element element, jobject parent) { 16 | 17 | jstring text = env->NewStringUTF(element.getText().c_str()); 18 | jobject jelement = env->NewObject(java_element_class, java_element_init, text, element.getType()); 19 | env->DeleteLocalRef(text); 20 | 21 | if (parent != NULL) { 22 | env->CallVoidMethod(jelement, java_element_setParent, parent); 23 | } 24 | 25 | if (element.size() > 0) { 26 | jobjectArray elements = (jobjectArray) env->NewObjectArray(element.size(), java_element_class, 0); 27 | for (int i=0; iSetObjectArrayElement(elements, i, childElement); 30 | env->DeleteLocalRef(childElement); 31 | } 32 | 33 | env->CallVoidMethod(jelement, java_element_setChildren, elements); 34 | } 35 | 36 | Bypass::Element::AttributeMap::iterator it = element.attrBegin(); 37 | for (; it != element.attrEnd(); ++it) { 38 | jstring name = env->NewStringUTF(it->first.c_str()); 39 | jstring value = env->NewStringUTF(it->second.c_str()); 40 | 41 | env->CallVoidMethod(jelement, java_element_addAttr, name, value); 42 | 43 | env->DeleteLocalRef(name); 44 | env->DeleteLocalRef(value); 45 | } 46 | 47 | return jelement; 48 | } 49 | 50 | JNIEXPORT jobject JNICALL Java_in_uncod_android_bypass_Bypass_processMarkdown 51 | (JNIEnv *env, jobject o, jstring markdown) { 52 | 53 | const char* str; 54 | str = env->GetStringUTFChars(markdown, NULL); 55 | 56 | Bypass::Parser parser; 57 | Bypass::Document document = parser.parse(str); 58 | 59 | env->ReleaseStringUTFChars(markdown, str); 60 | 61 | jclass java_document_class = env->FindClass("in/uncod/android/bypass/Document"); 62 | jmethodID java_document_init = env->GetMethodID(java_document_class, "", "([Lin/uncod/android/bypass/Element;)V"); 63 | java_element_class = env->FindClass("in/uncod/android/bypass/Element"); 64 | java_element_init = env->GetMethodID(java_element_class, "", "(Ljava/lang/String;I)V"); 65 | java_element_setChildren = env->GetMethodID(java_element_class, "setChildren", "([Lin/uncod/android/bypass/Element;)V"); 66 | java_element_setParent = env->GetMethodID(java_element_class, "setParent", "(Lin/uncod/android/bypass/Element;)V"); 67 | java_element_addAttr = env->GetMethodID(java_element_class, "addAttribute", "(Ljava/lang/String;Ljava/lang/String;)V"); 68 | 69 | jobjectArray elements = (jobjectArray) env->NewObjectArray(document.size(), java_element_class, 0); 70 | 71 | for (int i=0; iSetObjectArrayElement(elements, i, jelement); 74 | env->DeleteLocalRef(jelement); 75 | } 76 | 77 | jobject jdocument = env->NewObject(java_document_class, java_document_init, elements); 78 | 79 | return jdocument; 80 | } 81 | 82 | -------------------------------------------------------------------------------- /src/parser.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2013 Uncodin, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef BYPASS_PARSER_H 18 | #define BYPASS_PARSER_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | extern "C" { 30 | #include "markdown.h" 31 | } 32 | 33 | #include "document.h" 34 | #include "element.h" 35 | 36 | #define INPUT_UNIT 1024 37 | #define OUTPUT_UNIT 64 38 | 39 | namespace Bypass { 40 | 41 | class Parser { 42 | public: 43 | Parser(); 44 | ~Parser(); 45 | 46 | Document parse(const char* markdown); 47 | Document parse(const std::string &markdown); 48 | 49 | // Block Element Callbacks 50 | 51 | void parsedBlockCode(struct buf *ob, struct buf *text); 52 | void parsedBlockQuote(struct buf *ob, struct buf *text); 53 | void parsedHeader(struct buf *ob, struct buf *text, int level); 54 | void parsedHrule(struct buf *ob); 55 | void parsedList(struct buf *ob, struct buf *text, int flags); 56 | void parsedListItem(struct buf *ob, struct buf *text, int flags); 57 | void parsedParagraph(struct buf *ob, struct buf *text); 58 | 59 | // Span Element Callbacks 60 | 61 | int parsedAutolink(struct buf *ob, struct buf *link, enum mkd_autolink type); 62 | int parsedCodeSpan(struct buf *ob, struct buf *text); 63 | int parsedDoubleEmphasis(struct buf *ob, struct buf *text, char c); 64 | int parsedEmphasis(struct buf *ob, struct buf *text, char c); 65 | int parsedImage(struct buf *ob, struct buf *link, struct buf *title, struct buf *alt); 66 | int parsedTripleEmphasis(struct buf *ob, struct buf *text, char c); 67 | int parsedLinebreak(struct buf *ob); 68 | int parsedLink(struct buf *ob, struct buf *link, struct buf *title, struct buf *content); 69 | 70 | // Low Level Callbacks 71 | 72 | void parsedNormalText(struct buf *ob, struct buf *text); 73 | 74 | // Debugging 75 | 76 | void printBuf(struct buf *b); 77 | 78 | private: 79 | Document document; 80 | std::map elementSoup; 81 | int elementCount; 82 | void handleBlock(Type, struct buf *ob, struct buf *text = NULL, int extra = -1); 83 | void handleSpan(Type, struct buf *ob, struct buf *text, struct buf *extra = NULL, struct buf *extra2 = NULL, bool output = true); 84 | void handleNontextSpan(Type, struct buf *ob, struct buf *link, struct buf *title = NULL, struct buf *alt = NULL); 85 | void createSpan(const Element&, struct buf *ob); 86 | void appendElementMarker(struct buf *ob); 87 | void eraseTrailingControlCharacters(const std::string& controlCharacters); 88 | }; 89 | 90 | } 91 | 92 | #endif // BYPASS_PARSER_H 93 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPDisplaySettings.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Audun Holm Ellertsen on 4/30/13. 3 | // Copyright (c) 2013 Uncodin. All rights reserved. 4 | // 5 | // To change the template use AppCode | Preferences | File Templates. 6 | // 7 | 8 | 9 | #import "BPAttributedStringConverter.h" 10 | #import 11 | #import "BPDisplaySettings.h" 12 | 13 | 14 | @implementation BPDisplaySettings 15 | 16 | - (id)init 17 | { 18 | self = [super init]; 19 | if (self) { 20 | CGFloat systemFontSize = [UIFont systemFontSize]; 21 | 22 | self.defaultFont = [UIFont systemFontOfSize:systemFontSize]; 23 | self.boldFont = [UIFont boldSystemFontOfSize:systemFontSize]; 24 | self.italicFont = [UIFont italicSystemFontOfSize:systemFontSize]; 25 | self.monospaceFont = [UIFont fontWithName:@"Courier" size:systemFontSize - 2.f]; 26 | self.quoteFont = [UIFont fontWithName:@"Marion-Italic" size:systemFontSize - 2.f]; 27 | self.h1Font = [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:systemFontSize * 2.f]; 28 | self.h2Font = [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:systemFontSize * 1.8f]; 29 | self.h3Font = [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:systemFontSize * 1.6f]; 30 | self.h4Font = [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:systemFontSize * 1.4f]; 31 | self.h5Font = [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:systemFontSize * 1.2f]; 32 | self.h6Font = [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:systemFontSize]; 33 | 34 | self.defaultColor = [UIColor blackColor]; 35 | self.quoteColor = [UIColor darkGrayColor]; 36 | self.codeColor = [UIColor grayColor]; 37 | self.linkColor = [UIColor blueColor]; 38 | self.bulletIndentation = 13.0f; 39 | self.codeIndentation = 10.0f; 40 | self.quoteIndentation = 23.0f; 41 | self.paragraphSpacing = 20.0f; 42 | self.paragraphSpacingHeading = 10.0f; 43 | self.paragraphSpacingCode = 0.0f; 44 | 45 | self.paragraphLineSpacing = 1.2f; 46 | self.paragraphLineSpacingHeading = 1.2f; 47 | 48 | } 49 | return self; 50 | } 51 | 52 | - (UIFont *)boldItalicFont 53 | { 54 | if (_boldItalicFont == nil) { 55 | CTFontRef defaultFontRef = [self newCTFontRefFromUIFont:self.defaultFont]; 56 | CTFontSymbolicTraits traits = kCTFontBoldTrait | kCTFontItalicTrait; 57 | CTFontSymbolicTraits mask = kCTFontBoldTrait | kCTFontItalicTrait; 58 | CTFontRef boldItalicFontRef = CTFontCreateCopyWithSymbolicTraits(defaultFontRef, 0.f, NULL, traits, mask); 59 | assert(boldItalicFontRef != NULL); 60 | 61 | _boldItalicFont = [self UIFontFromCTFont:boldItalicFontRef]; 62 | CFRelease(defaultFontRef); 63 | CFRelease(boldItalicFontRef); 64 | } 65 | 66 | return _boldItalicFont; 67 | } 68 | 69 | #pragma mark - Private 70 | 71 | - (UIFont *)UIFontFromCTFont:(CTFontRef)ctFont 72 | { 73 | NSString *fontName = (__bridge_transfer NSString *) CTFontCopyName(ctFont, kCTFontPostScriptNameKey); 74 | CGFloat fontSize = CTFontGetSize(ctFont); 75 | 76 | return [UIFont fontWithName:fontName size:fontSize]; 77 | } 78 | 79 | - (CTFontRef)newCTFontRefFromUIFont:(UIFont *)font 80 | { 81 | return CTFontCreateWithName((__bridge CFStringRef)font.fontName, font.pointSize, NULL); 82 | } 83 | @end 84 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/BPTextViewController.mm: -------------------------------------------------------------------------------- 1 | // 2 | // BPTextViewController.m 3 | // BypassSample 4 | // 5 | // Created by Damian Carrillo on 3/1/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "BPTextViewController.h" 22 | #import "BPImageGetterSample.h" 23 | #import 24 | 25 | @interface BPTextViewController () 26 | @property (weak, nonatomic) IBOutlet UITextView *markdownView; 27 | @property (copy, nonatomic) NSAttributedString *attributedText; 28 | @end 29 | 30 | @implementation BPTextViewController 31 | 32 | /* 33 | Responds to a user's tap, and if necessary opens the embedded URL. 34 | */ 35 | - (IBAction)textViewWasTapped:(id)sender 36 | { 37 | CGPoint position = [sender locationInView:[self markdownView]]; 38 | position.y += [[self markdownView] contentOffset].y; 39 | 40 | UITextPosition *tapApproximation = [[self markdownView] closestPositionToPoint:position]; 41 | UITextPosition *beginning = [[self markdownView] beginningOfDocument]; 42 | NSUInteger characterIndex = [[self markdownView] offsetFromPosition:beginning toPosition:tapApproximation]; 43 | 44 | NSRange effectiveRange; 45 | effectiveRange.location = characterIndex; 46 | effectiveRange.length = 0; 47 | 48 | // Seek out a bypass link attribute. The attributed string renderer will embed the URL 49 | // as a string into the attributes dictionary of a link. 50 | 51 | if ([self attributedText].length != 0 ) { 52 | 53 | NSDictionary *attributes = [[self attributedText] attributesAtIndex:characterIndex effectiveRange:&effectiveRange]; 54 | NSString *linkHREF = attributes[BPLinkStyleAttributeName]; 55 | 56 | if (linkHREF != nil) { 57 | NSURL *linkURL = [NSURL URLWithString:linkHREF]; 58 | [[UIApplication sharedApplication] openURL:linkURL]; 59 | } 60 | } 61 | } 62 | 63 | - (void)viewWillAppear:(BOOL)animated 64 | { 65 | NSString *sample = [self sampleMarkdown]; 66 | 67 | BPParser *parser = [[BPParser alloc] init]; 68 | BPDocument *document = [parser parse:sample]; 69 | 70 | BPImageGetterSample *bpImageGetter = [[BPImageGetterSample alloc] init]; 71 | BPAttributedStringConverter *converter = [[BPAttributedStringConverter alloc] init]; 72 | NSAttributedString *attributedText = [converter convertDocument:document WithImageGetter:bpImageGetter]; 73 | 74 | // Warning: The attributed text is being set on a simple UITextView out of convenience. After this has been done, 75 | // Bypass' custom text attributes have been stripped. We save a copy to use as a point of reference for 76 | // user taps. 77 | 78 | [self setAttributedText:attributedText]; 79 | [[self markdownView] setAttributedText:attributedText]; 80 | } 81 | 82 | - (void)viewDidAppear:(BOOL)animated 83 | { 84 | [[self markdownView] flashScrollIndicators]; 85 | } 86 | 87 | @end 88 | -------------------------------------------------------------------------------- /dep/libsoldout/benchmark.c: -------------------------------------------------------------------------------- 1 | /* benchmark.c - main function for markdown module benchmarking */ 2 | 3 | /* 4 | * Copyright (c) 2009, Natacha Porté 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "markdown.h" 20 | #include "renderers.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #define READ_UNIT 1024 28 | #define OUTPUT_UNIT 64 29 | 30 | 31 | /* buffer statistics, to track some memleaks */ 32 | extern long buffer_stat_nb; 33 | extern size_t buffer_stat_alloc_bytes; 34 | 35 | 36 | 37 | /* markdown_file • performs markdown transformation on FILE* */ 38 | static void 39 | benchmark(FILE *in, int nb) { 40 | struct buf *ib, *ob; 41 | size_t ret, i, n; 42 | if (!in) return; 43 | n = (nb <= 1) ? 1 : nb; 44 | 45 | /* reading everything */ 46 | ib = bufnew(READ_UNIT); 47 | bufgrow(ib, READ_UNIT); 48 | while ((ret = fread(ib->data + ib->size, 1, 49 | ib->asize - ib->size, in)) > 0) { 50 | ib->size += ret; 51 | bufgrow(ib, ib->size + READ_UNIT); } 52 | 53 | /* performing markdown parsing */ 54 | for (i = 0; i < n; i += 1) { 55 | ob = bufnew(OUTPUT_UNIT); 56 | ob->size = 0; 57 | markdown(ob, ib, &mkd_xhtml); 58 | bufrelease(ob); } 59 | 60 | /* cleanup */ 61 | bufrelease(ib); } 62 | 63 | 64 | 65 | /* main • main function, interfacing STDIO with the parser */ 66 | int 67 | main(int argc, char **argv) { 68 | int nb = 1, i, j, f, files = 0; 69 | FILE *in = 0; 70 | 71 | /* looking for a count number */ 72 | if (argc > 1) { 73 | for (i = 1; i < argc; i += 1) 74 | if (argv[i][0] == '-' && argv[i][1] == '-') 75 | nb = atoi(argv[i] + 2); 76 | else files += 1; 77 | if (nb < 1) { 78 | fprintf(stderr, "Usage: %s [--] " 79 | "[file] [file] ...\n", argv[0]); 80 | return 2; } } 81 | 82 | /* if no file is given, using stdin as the only file */ 83 | if (files <= 0) { 84 | in = stdin; 85 | files = 1; } 86 | 87 | /* performing the markdown */ 88 | f = 0; 89 | for (j = 0; j < files; j += 1) { 90 | if (in != stdin) { 91 | f += 1; 92 | while (f < argc 93 | && argv[f][0] == '-' && argv[f][1] == '-') 94 | f += 1; 95 | if (f >= argc) break; 96 | in = fopen(argv[f], "r"); 97 | if (!in) { 98 | fprintf(stderr, "Unable to open \"%s\": %s\n", 99 | argv[f], strerror(errno)); 100 | continue; } } 101 | benchmark(in, nb); 102 | if (in != stdin) fclose(in); } 103 | 104 | /* memory checks */ 105 | if (buffer_stat_nb) 106 | fprintf(stderr, "Warning: %ld buffers still active\n", 107 | buffer_stat_nb); 108 | if (buffer_stat_alloc_bytes) 109 | fprintf(stderr, "Warning: %zu bytes still allocated\n", 110 | buffer_stat_alloc_bytes); 111 | return 0; } 112 | 113 | /* vim: set filetype=c: */ 114 | -------------------------------------------------------------------------------- /platform/ios/Bypass/BypassTests/BPElementTests.mm: -------------------------------------------------------------------------------- 1 | #import 2 | #import "BPElementPrivate.h" 3 | 4 | @interface BPElementTests : SenTestCase 5 | @end 6 | 7 | @implementation BPElementTests 8 | { 9 | BPElement *element; 10 | } 11 | 12 | - (void)setUp 13 | { 14 | using namespace Bypass; 15 | 16 | Element e0; 17 | e0.setType(PARAGRAPH); 18 | e0.setText("text"); 19 | e0.addAttribute("a", "A"); 20 | e0.addAttribute("b", "B"); 21 | 22 | Element e1; 23 | e1.setType(TEXT); 24 | e1.setText("one "); 25 | e0.append(e1); 26 | 27 | Element e2; 28 | e2.setType(DOUBLE_EMPHASIS); 29 | e2.setText("two"); 30 | e0.append(e2); 31 | 32 | Element e3; 33 | e3.setType(TEXT); 34 | e3.setText(" three"); 35 | e0.append(e3); 36 | 37 | element = [[BPElement alloc] initWithElement:e0]; 38 | } 39 | 40 | - (void)testInitialization 41 | { 42 | STAssertNotNil(element, @"Expected non-nil element"); 43 | } 44 | 45 | - (void)testElementTypeAccessor 46 | { 47 | STAssertEquals([element elementType], BPParagraph, @"Expected same type"); 48 | } 49 | 50 | - (void)testTextAccessor_forObjectEquality 51 | { 52 | STAssertEqualObjects([element text], @"text", @"Expected equivalent text"); 53 | } 54 | 55 | - (void)testTextAccessor_forPointerEquality 56 | { 57 | NSString *text = [element text]; 58 | STAssertEquals([element text], text, @"Expected same string"); 59 | } 60 | 61 | - (void)testAttributeAccessor_forObjectEquality 62 | { 63 | NSDictionary *expected = @{@"a": @"A", @"b": @"B"}; 64 | STAssertEqualObjects([element attributes], expected, @"Expected equivalent attributes"); 65 | } 66 | 67 | - (void)testAttributeAccessor_forPointerEquality 68 | { 69 | NSDictionary *attributes = [element attributes]; 70 | STAssertEquals([element attributes], attributes, @"Expected same attributes"); 71 | } 72 | 73 | - (void)testChildAccessor_forPointerEquality 74 | { 75 | NSArray *childElements = [element childElements]; 76 | STAssertEquals([element childElements], childElements, @"Expected same child elements"); 77 | } 78 | 79 | - (void)testChildElements 80 | { 81 | STAssertEquals([[element childElements] count], 3U, @"Expected 3 child elements"); 82 | STAssertEquals([[element childElements][0] elementType], BPText, @"Expected first element type to be BPText"); 83 | STAssertEquals([[element childElements][1] elementType], BPDoubleEmphasis, @"Expected second element type to be BPDoubleEmphasis"); 84 | STAssertEquals([[element childElements][2] elementType], BPText, @"Expected third element type to be BPText"); 85 | } 86 | 87 | - (void)testIsBlockElementAccessor 88 | { 89 | STAssertEquals([element isBlockElement], YES, @"Expected a block element"); 90 | STAssertEquals([[element childElements][0] isBlockElement], NO, @"Expected a span element"); 91 | } 92 | 93 | - (void)testForParentElement 94 | { 95 | BPElement *child = [element childElements][0]; 96 | STAssertEquals([child parentElement], element, @"Expected parent element to be specified"); 97 | } 98 | 99 | #if __has_feature(objc_subscripting) 100 | 101 | - (void)testNumericSubscripting 102 | { 103 | STAssertEquals(element[0], [[element childElements] objectAtIndex:0], @"Expected element subscripting to return a child element"); 104 | } 105 | 106 | - (void)testAlphabeticSubscripting 107 | { 108 | STAssertEqualObjects(element[@"a"], @"A", @"Expected alphabetic subscripting to return an attribute"); 109 | } 110 | 111 | #endif 112 | 113 | @end 114 | -------------------------------------------------------------------------------- /src/element.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2013 Uncodin, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #include "element.h" 18 | 19 | namespace Bypass { 20 | 21 | Element::Element() 22 | : text() 23 | , attributes() 24 | { 25 | type = PARAGRAPH; 26 | } 27 | 28 | Element::~Element() { 29 | 30 | } 31 | 32 | void Element::setText(const std::string& text) { 33 | this->text = text; 34 | } 35 | 36 | const std::string& Element::getText() { 37 | return text; 38 | } 39 | 40 | void Element::addAttribute(const std::string& name, const std::string& value) { 41 | attributes.insert(std::make_pair(name, value)); 42 | } 43 | 44 | std::string Element::getAttribute(const std::string& name) { 45 | return attributes[name]; 46 | } 47 | 48 | Element::AttributeMap::iterator Element::attrBegin() { 49 | return attributes.begin(); 50 | } 51 | 52 | Element::AttributeMap::iterator Element::attrEnd() { 53 | return attributes.end(); 54 | } 55 | 56 | size_t Element::attrSize() const { 57 | return attributes.size(); 58 | } 59 | 60 | void Element::append(const Element& child) { 61 | children.push_back(Element(child)); 62 | } 63 | 64 | Element Element::operator[](size_t i) { 65 | return children[i]; 66 | } 67 | 68 | void Element::setType(Type type) { 69 | this->type = type; 70 | } 71 | 72 | Type Element::getType() { 73 | return type; 74 | } 75 | 76 | bool Element::isBlockElement() { 77 | return (type & 0x100) == 0x000; 78 | } 79 | 80 | bool Element::isSpanElement() { 81 | return (type & 0x100) == 0x100; 82 | } 83 | 84 | size_t Element::size() { 85 | return children.size(); 86 | } 87 | 88 | std::ostream& operator<<(std::ostream& out, const Element& element) { 89 | 90 | std::string type; 91 | 92 | switch (element.type) { 93 | case BLOCK_CODE: 94 | type = "BLOCK_CODE"; 95 | break; 96 | case BLOCK_QUOTE: 97 | type = "BLOCK_QUOTE"; 98 | break; 99 | case BLOCK_HTML: 100 | type = "BLOCK_HTML"; 101 | break; 102 | case HEADER: 103 | type = "HEADER"; 104 | break; 105 | case HRULE: 106 | type = "HRULE"; 107 | break; 108 | case LIST: 109 | type = "LIST"; 110 | break; 111 | case LIST_ITEM: 112 | type = "LIST_ITEM"; 113 | break; 114 | case PARAGRAPH: 115 | type = "PARAGRAPH"; 116 | break; 117 | case TABLE: 118 | type = "TABLE"; 119 | break; 120 | case TABLE_CELL: 121 | type = "TABLE_CELL"; 122 | break; 123 | case TABLE_ROW: 124 | type = "TABLE_ROW"; 125 | break; 126 | case AUTOLINK: 127 | type = "AUTOLINK"; 128 | break; 129 | case CODE_SPAN: 130 | type = "CODE_SPAN"; 131 | break; 132 | case DOUBLE_EMPHASIS: 133 | type = "DOUBLE_EMPHASIS"; 134 | break; 135 | case EMPHASIS: 136 | type = "EMPHASIS"; 137 | break; 138 | case IMAGE: 139 | type = "IMAGE"; 140 | break; 141 | case LINEBREAK: 142 | type = "LINEBREAK"; 143 | break; 144 | case LINK: 145 | type = "LINK"; 146 | break; 147 | case RAW_HTML_TAG: 148 | type = "RAW_HTML_TAG"; 149 | break; 150 | case TRIPLE_EMPHASIS: 151 | type = "TRIPLE_EMPHASIS"; 152 | break; 153 | case TEXT: 154 | type = "TEXT"; 155 | break; 156 | case STRIKETHROUGH: 157 | type = "STRIKETHROUGH"; 158 | break; 159 | } 160 | 161 | out << "Element {" << std::endl; 162 | out << " type: " << type << std::endl; 163 | out << ", text: \"" << element.text << "\"" << std::endl; 164 | out << "}" << std::endl; 165 | return out; 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /platform/android/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.sonatype.oss 7 | oss-parent 8 | 7 9 | 10 | 11 | in.uncod.android.bypass 12 | parent 13 | 1.2-SNAPSHOT 14 | pom 15 | 16 | Bypass (Parent) 17 | Skip the HTML, Bypass takes markdown and renders it directly on Android and iOS. 18 | http://uncodin.github.com/bypass/ 19 | 2013 20 | 21 | 22 | library 23 | functional-test 24 | functional-test-tests 25 | 26 | 27 | 28 | https://github.com/Uncodin/bypass/ 29 | scm:git:git://github.com/Uncodin/bypass.git 30 | scm:git:git@github.com:Uncodin/bypass.git 31 | HEAD 32 | 33 | 34 | 35 | 36 | Colin Edwards 37 | colin@recursivepenguin.com 38 | cedwards 39 | http://recursivepenguin.com/ 40 | -6 41 | 42 | architect 43 | developer 44 | 45 | 46 | 47 | Damian Carrillo 48 | damian@uncod.in 49 | dcarrillo 50 | -6 51 | 52 | architect 53 | developer 54 | 55 | 56 | 57 | 58 | 59 | Uncodin 60 | http://uncod.in/ 61 | 62 | 63 | 64 | GitHub Issues 65 | https://github.com/Uncodin/bypass/issues 66 | 67 | 68 | 69 | 70 | Apache License Version 2.0 71 | http://www.apache.org/licenses/LICENSE-2.0.txt 72 | repo 73 | 74 | 75 | 76 | 77 | UTF-8 78 | UTF-8 79 | 80 | 4.1.1.4 81 | 82 | 4.10 83 | 84 | 85 | 86 | 87 | 88 | com.google.android 89 | android 90 | ${android.version} 91 | 92 | 93 | com.google.android 94 | android-test 95 | 4.1.1.4 96 | provided 97 | 98 | 99 | junit 100 | junit 101 | ${junit.version} 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | com.jayway.maven.plugins.android.generation2 111 | android-maven-plugin 112 | 3.8.2 113 | 114 | 115 | 116 | 19 117 | 118 | 119 | 120 | 121 | 122 | maven-compiler-plugin 123 | 2.5.1 124 | 125 | 1.6 126 | 1.6 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | org.apache.maven.plugins 135 | maven-release-plugin 136 | 2.3.2 137 | 138 | true 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /dep/libsoldout/markdown.h: -------------------------------------------------------------------------------- 1 | /* markdown.h - generic markdown parser */ 2 | 3 | /* 4 | * Copyright (c) 2009, Natacha Porté 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef LITHIUM_MARKDOWN_H 20 | #define LITHIUM_MARKDOWN_H 21 | 22 | #include "buffer.h" 23 | 24 | 25 | /******************** 26 | * TYPE DEFINITIONS * 27 | ********************/ 28 | 29 | /* mkd_autolink • type of autolink */ 30 | enum mkd_autolink { 31 | MKDA_NOT_AUTOLINK, /* used internally when it is not an autolink*/ 32 | MKDA_NORMAL, /* normal http/http/ftp/etc link */ 33 | MKDA_EXPLICIT_EMAIL, /* e-mail link with explit mailto: */ 34 | MKDA_IMPLICIT_EMAIL /* e-mail link without mailto: */ 35 | }; 36 | 37 | /* mkd_renderer • functions for rendering parsed data */ 38 | struct mkd_renderer { 39 | /* document level callbacks */ 40 | void (*prolog)(struct buf *ob, void *opaque); 41 | void (*epilog)(struct buf *ob, void *opaque); 42 | 43 | /* block level callbacks - NULL skips the block */ 44 | void (*blockcode)(struct buf *ob, struct buf *text, void *opaque); 45 | void (*blockquote)(struct buf *ob, struct buf *text, void *opaque); 46 | void (*blockhtml)(struct buf *ob, struct buf *text, void *opaque); 47 | void (*header)(struct buf *ob, struct buf *text, 48 | int level, void *opaque); 49 | void (*hrule)(struct buf *ob, void *opaque); 50 | void (*list)(struct buf *ob, struct buf *text, int flags, void *opaque); 51 | void (*listitem)(struct buf *ob, struct buf *text, 52 | int flags, void *opaque); 53 | void (*paragraph)(struct buf *ob, struct buf *text, void *opaque); 54 | void (*table)(struct buf *ob, struct buf *head_row, struct buf *rows, 55 | void *opaque); 56 | void (*table_cell)(struct buf *ob, struct buf *text, int flags, 57 | void *opaque); 58 | void (*table_row)(struct buf *ob, struct buf *cells, int flags, 59 | void *opaque); 60 | 61 | /* span level callbacks - NULL or return 0 prints the span verbatim */ 62 | int (*autolink)(struct buf *ob, struct buf *link, 63 | enum mkd_autolink type, void *opaque); 64 | int (*codespan)(struct buf *ob, struct buf *text, void *opaque); 65 | int (*double_emphasis)(struct buf *ob, struct buf *text, 66 | char c, void *opaque); 67 | int (*emphasis)(struct buf *ob, struct buf *text, char c,void*opaque); 68 | int (*image)(struct buf *ob, struct buf *link, struct buf *title, 69 | struct buf *alt, void *opaque); 70 | int (*linebreak)(struct buf *ob, void *opaque); 71 | int (*link)(struct buf *ob, struct buf *link, struct buf *title, 72 | struct buf *content, void *opaque); 73 | int (*raw_html_tag)(struct buf *ob, struct buf *tag, void *opaque); 74 | int (*triple_emphasis)(struct buf *ob, struct buf *text, 75 | char c, void *opaque); 76 | 77 | /* low level callbacks - NULL copies input directly into the output */ 78 | void (*entity)(struct buf *ob, struct buf *entity, void *opaque); 79 | void (*normal_text)(struct buf *ob, struct buf *text, void *opaque); 80 | 81 | /* renderer data */ 82 | int max_work_stack; /* prevent arbitrary deep recursion, cf README */ 83 | const char *emph_chars; /* chars that trigger emphasis rendering */ 84 | void *opaque; /* opaque data send to every rendering callback */ 85 | }; 86 | 87 | 88 | 89 | /********* 90 | * FLAGS * 91 | *********/ 92 | 93 | /* list/listitem flags */ 94 | #define MKD_LIST_ORDERED 1 95 | #define MKD_LI_BLOCK 2 /*
  • containing block data */ 96 | 97 | /* table cell flags */ 98 | #define MKD_CELL_ALIGN_DEFAULT 0 99 | #define MKD_CELL_ALIGN_LEFT 1 100 | #define MKD_CELL_ALIGN_RIGHT 2 101 | #define MKD_CELL_ALIGN_CENTER 3 /* LEFT | RIGHT */ 102 | #define MKD_CELL_ALIGN_MASK 3 103 | #define MKD_CELL_HEAD 4 104 | 105 | 106 | 107 | /********************** 108 | * EXPORTED FUNCTIONS * 109 | **********************/ 110 | 111 | /* markdown • parses the input buffer and renders it into the output buffer */ 112 | void 113 | markdown(struct buf *ob, struct buf *ib, const struct mkd_renderer *rndr); 114 | 115 | 116 | #endif /* ndef LITHIUM_MARKDOWN_H */ 117 | 118 | /* vim: set filetype=c: */ 119 | -------------------------------------------------------------------------------- /dep/libsoldout/array.h: -------------------------------------------------------------------------------- 1 | /* array.h - automatic dynamic array for pointers */ 2 | 3 | /* 4 | * Copyright (c) 2008, Natacha Porté 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef LITHIUM_ARRAY_H 20 | #define LITHIUM_ARRAY_H 21 | 22 | #include 23 | 24 | 25 | /******************** 26 | * TYPE DEFINITIONS * 27 | ********************/ 28 | 29 | /* struct array • generic linear array */ 30 | struct array { 31 | void* base; 32 | int size; 33 | int asize; 34 | size_t unit; }; 35 | 36 | 37 | /* struct parray • array of pointers */ 38 | struct parray { 39 | void ** item; 40 | int size; 41 | int asize; }; 42 | 43 | 44 | /* array_cmp_fn • comparison functions for sorted arrays */ 45 | typedef int (*array_cmp_fn)(void *key, void *array_entry); 46 | 47 | 48 | 49 | /*************************** 50 | * GENERIC ARRAY FUNCTIONS * 51 | ***************************/ 52 | 53 | /* arr_adjust • shrink the allocated memory to fit exactly the needs */ 54 | int 55 | arr_adjust(struct array *); 56 | 57 | /* arr_free • frees the structure contents (buf NOT the struct itself) */ 58 | void 59 | arr_free(struct array *); 60 | 61 | /* arr_grow • increases the array size to fit the given number of elements */ 62 | int 63 | arr_grow(struct array *, int); 64 | 65 | /* arr_init • initialization of the contents of the struct */ 66 | void 67 | arr_init(struct array *, size_t); 68 | 69 | /* arr_insert • inserting elements nb before the nth one */ 70 | int 71 | arr_insert(struct array *, int nb, int n); 72 | 73 | /* arr_item • returns a pointer to the n-th element */ 74 | void * 75 | arr_item(struct array *, int); 76 | 77 | /* arr_newitem • returns the index of a new element appended to the array */ 78 | int 79 | arr_newitem(struct array *); 80 | 81 | /* arr_remove • removes the n-th elements of the array */ 82 | void 83 | arr_remove(struct array *, int); 84 | 85 | /* arr_sorted_find • O(log n) search in a sorted array, returning entry */ 86 | /* equivalent to bsearch(key, arr->base, arr->size, arr->unit, cmp) */ 87 | void * 88 | arr_sorted_find(struct array *, void *key, array_cmp_fn cmp); 89 | 90 | /* arr_sorted_find_i • O(log n) search in a sorted array, 91 | * returning index of the smallest element larger than the key */ 92 | int 93 | arr_sorted_find_i(struct array *, void *key, array_cmp_fn cmp); 94 | 95 | 96 | /*************************** 97 | * POINTER ARRAY FUNCTIONS * 98 | ***************************/ 99 | 100 | /* parr_adjust • shrinks the allocated memory to fit exactly the needs */ 101 | int 102 | parr_adjust(struct parray *); 103 | 104 | /* parr_free • frees the structure contents (buf NOT the struct itself) */ 105 | void 106 | parr_free(struct parray *); 107 | 108 | /* parr_grow • increases the array size to fit the given number of elements */ 109 | int 110 | parr_grow(struct parray *, int); 111 | 112 | /* parr_init • initialization of the struct (which is equivalent to zero) */ 113 | void 114 | parr_init(struct parray *); 115 | 116 | /* parr_insert • inserting nb elements before the nth one */ 117 | int 118 | parr_insert(struct parray *, int nb, int n); 119 | 120 | /* parr_pop • pops the last item of the array and returns it */ 121 | void * 122 | parr_pop(struct parray *); 123 | 124 | /* parr_push • pushes a pointer at the end of the array (= append) */ 125 | int 126 | parr_push(struct parray *, void *); 127 | 128 | /* parr_remove • removes the n-th element of the array and returns it */ 129 | void * 130 | parr_remove(struct parray *, int); 131 | 132 | /* parr_sorted_find • O(log n) search in a sorted array, returning entry */ 133 | void * 134 | parr_sorted_find(struct parray *, void *key, array_cmp_fn cmp); 135 | 136 | /* parr_sorted_find_i • O(log n) search in a sorted array, 137 | * returning index of the smallest element larger than the key */ 138 | int 139 | parr_sorted_find_i(struct parray *, void *key, array_cmp_fn cmp); 140 | 141 | /* parr_top • returns the top the stack (i.e. the last element of the array) */ 142 | void * 143 | parr_top(struct parray *); 144 | 145 | 146 | #endif /* ndef LITHIUM_ARRAY_H */ 147 | 148 | /* vim: set filetype=c: */ 149 | -------------------------------------------------------------------------------- /dep/libsoldout/buffer.h: -------------------------------------------------------------------------------- 1 | /* buffer.h - automatic buffer structure */ 2 | 3 | /* 4 | * Copyright (c) 2008, Natacha Porté 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef LITHIUM_BUFFER_H 20 | #define LITHIUM_BUFFER_H 21 | 22 | #include 23 | 24 | 25 | /******************** 26 | * TYPE DEFINITIONS * 27 | ********************/ 28 | 29 | /* struct buf • character array buffer */ 30 | struct buf { 31 | char * data; /* actual character data */ 32 | size_t size; /* size of the string */ 33 | size_t asize; /* allocated size (0 = volatile buffer) */ 34 | size_t unit; /* reallocation unit size (0 = read-only buffer) */ 35 | int ref; }; /* reference count */ 36 | 37 | 38 | 39 | /********** 40 | * MACROS * 41 | **********/ 42 | 43 | /* CONST_BUF • global buffer from a string litteral */ 44 | #define CONST_BUF(name, string) \ 45 | static struct buf name = { string, sizeof string -1, sizeof string } 46 | 47 | 48 | /* VOLATILE_BUF • macro for creating a volatile buffer on the stack */ 49 | #define VOLATILE_BUF(name, strname) \ 50 | struct buf name = { strname, strlen(strname) } 51 | 52 | 53 | /* BUFPUTSL • optimized bufputs of a string litteral */ 54 | #define BUFPUTSL(output, litteral) \ 55 | bufput(output, litteral, sizeof litteral - 1) 56 | 57 | 58 | /*********************** 59 | * FUNCTION ATTRIBUTES * 60 | ***********************/ 61 | 62 | /* BUF_ALLOCATOR • the function returns a completely new ponter */ 63 | #ifdef __GNUC__ 64 | #define BUF_ALLOCATOR \ 65 | __attribute__ ((malloc)) 66 | #else 67 | #define BUF_ALLOCATOR 68 | #endif 69 | 70 | 71 | /* BUF_PRINTF_LIKE • marks the function as behaving like printf */ 72 | #ifdef __GNUC__ 73 | #define BUF_PRINTF_LIKE(format_index, first_variadic_index) \ 74 | __attribute__ ((format (printf, format_index, first_variadic_index))); 75 | #else 76 | #define BUF_PRINTF_LIKE(format_index, first_variadic_index) 77 | #endif 78 | 79 | 80 | /******************** 81 | * BUFFER FUNCTIONS * 82 | ********************/ 83 | 84 | /* bufcasecmp • case-insensitive buffer comparison */ 85 | int 86 | bufcasecmp(const struct buf *, const struct buf *); 87 | 88 | /* bufcmp • case-sensitive buffer comparison */ 89 | int 90 | bufcmp(const struct buf *, const struct buf *); 91 | 92 | /* bufcmps • case-sensitive comparison of a string to a buffer */ 93 | int 94 | bufcmps(const struct buf *, const char *); 95 | 96 | /* bufdup • buffer duplication */ 97 | struct buf * 98 | bufdup(const struct buf *, size_t) 99 | BUF_ALLOCATOR; 100 | 101 | /* bufgrow • increasing the allocated size to the given value */ 102 | int 103 | bufgrow(struct buf *, size_t); 104 | 105 | /* bufnew • allocation of a new buffer */ 106 | struct buf * 107 | bufnew(size_t) 108 | BUF_ALLOCATOR; 109 | 110 | /* bufnullterm • NUL-termination of the string array (making a C-string) */ 111 | void 112 | bufnullterm(struct buf *); 113 | 114 | /* bufprintf • formatted printing to a buffer */ 115 | void 116 | bufprintf(struct buf *, const char *, ...) 117 | BUF_PRINTF_LIKE(2, 3); 118 | 119 | /* bufput • appends raw data to a buffer */ 120 | void 121 | bufput(struct buf *, const void*, size_t); 122 | 123 | /* bufputs • appends a NUL-terminated string to a buffer */ 124 | void 125 | bufputs(struct buf *, const char*); 126 | 127 | /* bufputc • appends a single char to a buffer */ 128 | void 129 | bufputc(struct buf *, char); 130 | 131 | /* bufrelease • decrease the reference count and free the buffer if needed */ 132 | void 133 | bufrelease(struct buf *); 134 | 135 | /* bufreset • frees internal data of the buffer */ 136 | void 137 | bufreset(struct buf *); 138 | 139 | /* bufset • safely assigns a buffer to another */ 140 | void 141 | bufset(struct buf **, struct buf *); 142 | 143 | /* bufslurp • removes a given number of bytes from the head of the array */ 144 | void 145 | bufslurp(struct buf *, size_t); 146 | 147 | /* buftoi • converts the numbers at the beginning of the buf into an int */ 148 | int 149 | buftoi(struct buf *, size_t, size_t *); 150 | 151 | 152 | 153 | #ifdef BUFFER_STDARG 154 | #include 155 | 156 | /* vbufprintf • stdarg variant of formatted printing into a buffer */ 157 | void 158 | vbufprintf(struct buf *, const char*, va_list); 159 | 160 | #endif /* def BUFFER_STDARG */ 161 | 162 | #endif /* ndef LITHIUM_BUFFER_H */ 163 | 164 | /* vim: set filetype=c: */ 165 | -------------------------------------------------------------------------------- /platform/ios/README.md: -------------------------------------------------------------------------------- 1 | # Bypass iOS 2 | 3 | Bypass is a markdown rendering library that can directly render markdown as 4 | stylized text to a `UIView`. The Bypass git repository also contains an Android 5 | project that accomplish the same task. In the git repo, there is also code that 6 | handles markdown parsing and representing that markdown as a tree structure, 7 | similar to the HTML DOM. This code is shared between both platforms. 8 | 9 | Bypass is very easy to use. Ultimately, you will end up creating a 10 | `BPMarkdownView`, supplying that view with markdown as an `NSString`, and then 11 | displaying it like you would any other view in your heirarchy. `BPMarkdownView` 12 | descends from `UIScrollView`, so you can supply large bodies of markdown. 13 | 14 | It features nicely stylized text for typical usage, tappable links, and a smooth 15 | crossfade between representations for different device orientations. 16 | 17 | ## Requirements 18 | 19 | Bypass requires iOS version 6.0 or greater. You will also need to 20 | [install Boost](http://www.boost.org/doc/libs/1_53_0/more/getting_started/index.html) 21 | if you don't already have it installed. 22 | 23 | ## Setup 24 | 25 | Clone bypass from Github. 26 | 27 | git clone git@github.com:Uncodin/bypass.git 28 | 29 | Drag `bypass/platform/ios/Bypass/Bypass.xcodeproj` into your project from the Finder. 30 | 31 | ![Drag Bypass.xcodeproj into your project](images/dragXcodeproj.png) 32 | 33 | Open your target settings. 34 | 35 | ![Open your target settings](images/target.png) 36 | 37 | Select the Build Phases tab. 38 | 39 | ![Select the Build Phases tab](images/buildPhases.png) 40 | 41 | Add Bypass as a target dependency. 42 | 43 | ![Add Bypass as a target dependency](images/targetDependency.png) 44 | 45 | Add `libBypass.a`, `CoreGraphics.framework`, `CoreText.framework`, 46 | `Foundation.framework`, and `QuartzCore.framework`, and `UIKit.framework` to the 47 | list of required libraries to link against, if they aren't already included. 48 | 49 | ![Adding libraries the list of libraries to link against](images/linkLibraries.png) 50 | 51 | Modify your build settings so they have the following values: 52 | 53 | * Linking 54 | * **Other Linker Flags**: `-ObjC` 55 | * Search Paths 56 | * **Header Search Paths**: `$(SRCROOT)//Bypass/Bypass` 57 | * Apple LLVM Compile 4.2 - Language 58 | * **C++ Standard Library**: `libc++ (LLVM C++ standard library with C++11 support)` 59 | 60 | ![Modify your build settings](images/buildSettings.png) 61 | 62 | ## Usage 63 | 64 | Bypass is very easy to use in terms of displaying markdown. Essentially, you 65 | directly instantiate a `BPMarkdownView` and supply it with markdown to render. 66 | It handles the rest. An example would be: 67 | 68 | ```objc 69 | // Initialize the markdown view 70 | CGRect markdownRect = CGRectMake(0.f, 0.f, 100.f, 100.f); 71 | BPMarkdownView *markdownView = [[BPMarkdownView alloc] initWithFrame:markdownRect]; 72 | 73 | // Obtain some markdown 74 | NSString *markdown = @"" 75 | "# Hello, world!" 76 | "" 77 | "This is my text body. There are many more like it, " 78 | "but this one is mine."; 79 | 80 | // Supply the markdown view with markdown to render 81 | [markdownView setMarkdown:markdown]; 82 | 83 | // Add the markdown view to a superview 84 | [[self view] addSubview:markdownView]; 85 | ``` 86 | 87 | Feel free to directly embed a `BPMarkdownView` in a Nib or Storyboard, but 88 | ensure that you have configured your **Other Linker Flags** to contain `-ObjC` 89 | if you do this. The BypassSample project included in the repo shows an example 90 | of this use case. 91 | 92 | ## Performance 93 | 94 | It's a bit challenging to compare Bypass to, say a `UITextView` representing an 95 | attributed string, because the interesting work happens in different places. 96 | Essentially, what I deemed most appropriate to compare were a `UIViewController` 97 | that populates a `UITextView` with an `NSAttributedString`, and 98 | `BPMarkdownView`'s `layoutSubviews` method. A `UITextView` uses a conversion 99 | process that leverages HTML to display the text in a stylized manner. A 100 | `BPMarkdownView` drops down to the Core Text layer and renders the attributed 101 | string directly. 102 | 103 | The results are as follows (I included `drawRect:` for an additional degree 104 | of transparency): 105 | 106 | Running Time Self Symbol Name 107 | 135.0ms 36.3% 94.0 -[BPTextViewController viewWillAppear:] 108 | 39.0ms 10.5% 0.0 -[BPMarkdownView layoutSubviews] 109 | 5.0ms 1.3% 5.0 -[BPMarkdownPageView drawRect:] 110 | 111 | I encourage you to profile the BypassSample project yourself. It's interesting 112 | to see everything a `UITextView` is doing, and for what it's doing, it's doing 113 | it very quickly. Bypass is simply faster, though, because it was designed for 114 | this particular purpose from the ground up. 115 | 116 | ## Conclusion 117 | 118 | I hope you enjoy Bypass. Remember that it is a new project, and that there are 119 | probably many enhancements and improvements to be had. Feel free to get involved 120 | and open [issues and enhancements](https://github.com/Uncodin/bypass/issues), 121 | and also feel free to contribute back. 122 | -------------------------------------------------------------------------------- /dep/libsoldout/mkd2html.c: -------------------------------------------------------------------------------- 1 | /* main.c - main function for markdown module testing */ 2 | 3 | /* 4 | * Copyright (c) 2009, Natacha Porté 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "markdown.h" 20 | #include "renderers.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define READ_UNIT 1024 29 | #define OUTPUT_UNIT 64 30 | 31 | 32 | /* buffer statistics, to track some memleaks */ 33 | extern long buffer_stat_nb; 34 | extern size_t buffer_stat_alloc_bytes; 35 | 36 | 37 | 38 | /* usage • print the option list */ 39 | void 40 | usage(FILE *out, const char *name) { 41 | fprintf(out, "Usage: %s [-h | -x] [-d | -m | -n] [input-file]\n\n", 42 | name); 43 | fprintf(out, "\t-d, --discount\n" 44 | "\t\tEnable some Discount extensions (image size specficiation,\n" 45 | "\t\tclass blocks and 'abbr:', 'class:', 'id:' and 'raw:'\n" 46 | "\t\tpseudo-protocols)\n" 47 | "\t-H, --html\n" 48 | "\t\tOutput HTML-style self-closing tags (e.g.
    )\n" 49 | "\t-h, --help\n" 50 | "\t\tDisplay this help text and exit without further processing\n" 51 | "\t-m, --markdown\n" 52 | "\t\tDisable all extensions and use strict markdown syntax\n" 53 | "\t-n, --natext\n" 54 | "\t\tEnable support Discount extensions and Natasha's own\n" 55 | "\t\textensions (id header attribute, class paragraph attribute,\n" 56 | "\t\t'ins' and 'del' elements, and plain span elements)\n" 57 | "\t-x, --xhtml\n" 58 | "\t\tOutput XHTML-style self-closing tags (e.g.
    )\n"); } 59 | 60 | 61 | 62 | /* main • main function, interfacing STDIO with the parser */ 63 | int 64 | main(int argc, char **argv) { 65 | struct buf *ib, *ob; 66 | size_t ret; 67 | FILE *in = stdin; 68 | const struct mkd_renderer *hrndr, *xrndr; 69 | const struct mkd_renderer **prndr; 70 | int ch, argerr, help; 71 | struct option longopts[] = { 72 | { "discount", no_argument, 0, 'd' }, 73 | { "html", no_argument, 0, 'H' }, 74 | { "help", no_argument, 0, 'h' }, 75 | { "markdown", no_argument, 0, 'm' }, 76 | { "natext", no_argument, 0, 'n' }, 77 | { "xhtml", no_argument, 0, 'x' }, 78 | { 0, 0, 0, 0 } }; 79 | 80 | /* default options: strict markdown input, HTML output */ 81 | hrndr = &mkd_html; 82 | xrndr = &mkd_xhtml; 83 | prndr = &hrndr; 84 | 85 | /* argument parsing */ 86 | argerr = help = 0; 87 | while (!argerr && 88 | (ch = getopt_long(argc, argv, "dHhmnx", longopts, 0)) != -1) 89 | switch (ch) { 90 | case 'd': /* discount extension */ 91 | hrndr = &discount_html; 92 | xrndr = &discount_xhtml; 93 | break; 94 | case 'H': /* HTML output */ 95 | prndr = &hrndr; 96 | break; 97 | case 'h': /* display help */ 98 | argerr = help = 1; 99 | break; 100 | case 'm': /* strict markdown */ 101 | hrndr = &mkd_html; 102 | xrndr = &mkd_xhtml; 103 | break; 104 | case 'n': /* Discount + Natasha's extensions */ 105 | hrndr = &nat_html; 106 | xrndr = &nat_xhtml; 107 | break; 108 | case 'x': /* XHTML output */ 109 | prndr = &xrndr; 110 | break; 111 | default: 112 | argerr = 1; } 113 | if (argerr) { 114 | usage(help ? stdout : stderr, argv[0]); 115 | return help ? EXIT_SUCCESS : EXIT_FAILURE; } 116 | argc -= optind; 117 | argv += optind; 118 | 119 | /* opening the file if given from the command line */ 120 | if (argc > 0) { 121 | in = fopen(argv[0], "r"); 122 | if (!in) { 123 | fprintf(stderr,"Unable to open input file \"%s\": %s\n", 124 | argv[0], strerror(errno)); 125 | return 1; } } 126 | 127 | /* reading everything */ 128 | ib = bufnew(READ_UNIT); 129 | bufgrow(ib, READ_UNIT); 130 | while ((ret = fread(ib->data + ib->size, 1, 131 | ib->asize - ib->size, in)) > 0) { 132 | ib->size += ret; 133 | bufgrow(ib, ib->size + READ_UNIT); } 134 | if (in != stdin) fclose(in); 135 | 136 | /* performing markdown parsing */ 137 | ob = bufnew(OUTPUT_UNIT); 138 | markdown(ob, ib, *prndr); 139 | 140 | /* writing the result to stdout */ 141 | ret = fwrite(ob->data, 1, ob->size, stdout); 142 | if (ret < ob->size) 143 | fprintf(stderr, "Warning: only %zu output byte written, " 144 | "out of %zu\n", 145 | ret, 146 | ob->size); 147 | 148 | /* cleanup */ 149 | bufrelease(ib); 150 | bufrelease(ob); 151 | 152 | /* memory checks */ 153 | if (buffer_stat_nb) 154 | fprintf(stderr, "Warning: %ld buffers still active\n", 155 | buffer_stat_nb); 156 | if (buffer_stat_alloc_bytes) 157 | fprintf(stderr, "Warning: %zu bytes still allocated\n", 158 | buffer_stat_alloc_bytes); 159 | return 0; } 160 | 161 | /* vim: set filetype=c: */ 162 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPMarkdownPageView.m: -------------------------------------------------------------------------------- 1 | // 2 | // BPMarkdownPageView.m 3 | // Bypass 4 | // 5 | // Created by Damian Carrillo on 3/13/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "BPAttributedStringConverter.h" 22 | #import "BPDocument.h" 23 | #import "BPMarkdownPageView.h" 24 | 25 | #define SHOW_ATTRIBUTES_ON_TAP 0 26 | 27 | void 28 | BPContextFlipVertical(CGContextRef context, CGRect rect) 29 | { 30 | CGFloat h = CGRectGetHeight(rect); 31 | CGAffineTransform flipTransformation = CGAffineTransformMake(1, 0, // 0 32 | 0, -1, // 0 33 | 0, h); // 1 34 | CGContextConcatCTM(context, flipTransformation); 35 | } 36 | 37 | @implementation BPMarkdownPageView 38 | { 39 | CTFrameRef _textFrame; 40 | } 41 | 42 | - (id)initWithFrame:(CGRect)frame textFrame:(CTFrameRef)textFrame 43 | { 44 | self = [super initWithFrame:frame]; 45 | 46 | if (self != nil) { 47 | [self setBackgroundColor:[UIColor whiteColor]]; 48 | 49 | CFRetain(textFrame); 50 | _textFrame = textFrame; 51 | } 52 | 53 | return self; 54 | } 55 | 56 | - (void)dealloc 57 | { 58 | CFRelease(_textFrame); 59 | } 60 | 61 | - (void)drawRect:(CGRect)rect 62 | { 63 | CGContextRef context = UIGraphicsGetCurrentContext(); 64 | CGContextSetFillColorWithColor(context, [[self backgroundColor] CGColor]); 65 | CGContextFillRect(context, rect); 66 | 67 | CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]); 68 | CGContextSetTextMatrix(context, CGAffineTransformIdentity); 69 | BPContextFlipVertical(context, rect); 70 | 71 | CTFrameDraw(_textFrame, context); 72 | } 73 | 74 | - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 75 | { 76 | UITouch *touch = [touches anyObject]; 77 | 78 | if ([touch tapCount] == 1 && [touch phase] == UITouchPhaseEnded) { 79 | CGPoint touchPoint = [touch locationInView:self]; 80 | 81 | // Account for matrix flip 82 | 83 | touchPoint = CGPointMake(touchPoint.x, CGRectGetHeight([self frame]) - touchPoint.y); 84 | 85 | CFArrayRef lines = CTFrameGetLines(_textFrame); 86 | CFIndex lineCount = CFArrayGetCount(lines); 87 | CGPoint origins[lineCount]; 88 | 89 | CTFrameGetLineOrigins(_textFrame, CFRangeMake(0, lineCount), origins); 90 | 91 | CFIndex i; 92 | for (i = 0; i < lineCount; i++) { 93 | CTLineRef line = CFArrayGetValueAtIndex(lines, i); 94 | CGRect lineBounds = CTLineGetBoundsWithOptions(line, kCTLineBoundsUseOpticalBounds); 95 | 96 | lineBounds.origin.x += origins[i].x; 97 | lineBounds.origin.y += origins[i].y; 98 | 99 | if (CGRectContainsPoint(lineBounds, touchPoint)) { 100 | CFIndex stringIndex = CTLineGetStringIndexForPosition(line, touchPoint); 101 | 102 | if (stringIndex > 0 && 103 | touchPoint.x < CTLineGetOffsetForStringIndex(line, stringIndex, NULL)) { 104 | 105 | // Account for caret snapping when a boundary glyph's outer half has 106 | // been tapped 107 | 108 | --stringIndex; 109 | } 110 | 111 | CFArrayRef glyphRuns = CTLineGetGlyphRuns(line); 112 | CFIndex j, glyphRunCount = CFArrayGetCount(glyphRuns); 113 | 114 | for (j = 0; j < glyphRunCount; j++) { 115 | CTRunRef glyphRun = CFArrayGetValueAtIndex(glyphRuns, j); 116 | CFRange textRange = CTRunGetStringRange(glyphRun); 117 | 118 | if (textRange.location <= stringIndex && 119 | stringIndex < textRange.location + textRange.length) { 120 | 121 | CFDictionaryRef attributes = CTRunGetAttributes(glyphRun); 122 | 123 | #if SHOW_ATTRIBUTES_ON_TAP == 1 124 | // Shows what attributes are available on the tap point 125 | NSLog(@"%@", (__bridge NSDictionary *) attributes); 126 | #endif 127 | 128 | const void *value; 129 | value = CFDictionaryGetValue(attributes, 130 | (const void *) BPLinkStyleAttributeName); 131 | 132 | NSString *link = (__bridge NSString *) value; 133 | [[self linkDelegate] markdownPageView:self didHaveLinkTapped:link]; 134 | return; 135 | } 136 | } 137 | 138 | break; 139 | } 140 | } 141 | } 142 | 143 | [super touchesEnded:touches withEvent:event]; 144 | } 145 | 146 | @end 147 | -------------------------------------------------------------------------------- /dep/libsoldout/mkd2man.c: -------------------------------------------------------------------------------- 1 | /* mkd2man.c - man-page-formatted output from markdown text */ 2 | 3 | /* 4 | * Copyright (c) 2009, Baptiste Daroussin and Natacha Porté 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "markdown.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #define READ_UNIT 1024 26 | #define OUTPUT_UNIT 64 27 | 28 | 29 | /**************************** 30 | * MARKDOWN TO MAN RENDERER * 31 | ****************************/ 32 | 33 | void 34 | man_text_escape(struct buf *ob, char *src, size_t size) { 35 | size_t i = 0, org; 36 | while (i < size) { 37 | /* copying directly unescaped characters */ 38 | org = i; 39 | while (i < size && src[i] != '-') 40 | i += 1; 41 | if (i > org) bufput(ob, src + org, i - org); 42 | 43 | /* escaping */ 44 | if (i >= size) break; 45 | else if (src[i] == '-') BUFPUTSL(ob, "\\-"); 46 | i += 1; } } 47 | 48 | static void 49 | man_blockcode(struct buf *ob, struct buf *text, void *opaque) { 50 | if (ob->size) bufputc(ob, '\n'); 51 | BUFPUTSL(ob, ".nf\n"); 52 | if (text) man_text_escape(ob, text->data, text->size); 53 | BUFPUTSL(ob, ".fi\n"); } 54 | 55 | static int 56 | man_codespan(struct buf *ob, struct buf *text, void *opaque) { 57 | if (ob->size) bufputc(ob, '\n'); 58 | BUFPUTSL(ob, ".nf\n"); 59 | if (text) man_text_escape(ob, text->data, text->size); 60 | BUFPUTSL(ob, ".fi\n"); 61 | return 1; } 62 | 63 | static void 64 | man_header(struct buf *ob, struct buf *text, int level, void *opaque) { 65 | if (ob->size) bufputc(ob, '\n'); 66 | switch(level) { 67 | case 1: 68 | bufprintf(ob,".TH "); 69 | break; 70 | case 2: 71 | bufprintf(ob, ".SH "); 72 | break; 73 | case 3: 74 | bufprintf(ob, ".SS "); 75 | break; 76 | } 77 | if (text) bufput(ob, text->data, text->size); 78 | } 79 | 80 | static int 81 | man_double_emphasis(struct buf *ob, struct buf *text, char c, void *opaque) { 82 | if (!text || !text->size) return 0; 83 | BUFPUTSL(ob, "\\fB"); 84 | bufput(ob, text->data, text->size); 85 | BUFPUTSL(ob, "\\fP"); 86 | return 1; } 87 | 88 | static int 89 | man_emphasis(struct buf *ob, struct buf *text, char c, void *opaque) { 90 | if (!text || !text->size) return 0; 91 | BUFPUTSL(ob, "\\fI"); 92 | if (text) bufput(ob, text->data, text->size); 93 | BUFPUTSL(ob, "\\fP"); 94 | return 1; } 95 | 96 | static int 97 | man_linebreak(struct buf *ob, void *opaque) { 98 | BUFPUTSL(ob, "\n.LP\n"); 99 | return 1; } 100 | 101 | static void 102 | man_paragraph(struct buf *ob, struct buf *text, void *opaque) { 103 | if (ob->size) bufputc(ob, '\n'); 104 | BUFPUTSL(ob, ".TP\n"); 105 | if (text) bufput(ob, text->data, text->size); 106 | BUFPUTSL(ob, "\n"); } 107 | 108 | static void 109 | man_list(struct buf *ob, struct buf *text, int flags, void *opaque) { 110 | if (ob->size) bufputc(ob, '\n'); 111 | if (flags & MKD_LIST_ORDERED) 112 | BUFPUTSL(ob,"\n.nr step 0 1\n"); 113 | else 114 | BUFPUTSL(ob,".\n"); 115 | if (text) bufput(ob, text->data, text->size); 116 | BUFPUTSL(ob, "\n"); } 117 | 118 | static void 119 | man_listitem(struct buf *ob, struct buf *text, int flags, void *opaque) { 120 | if (flags & MKD_LIST_ORDERED) 121 | BUFPUTSL(ob, ".IP \\n+[step]\n"); 122 | else 123 | BUFPUTSL(ob, ".IP \\[bu] 2 \n"); 124 | 125 | if (text) { 126 | while (text->size && text->data[text->size - 1] == '\n') 127 | text->size -= 1; 128 | bufput(ob, text->data, text->size); } 129 | BUFPUTSL(ob, "\n"); } 130 | 131 | static void 132 | man_normal_text(struct buf *ob, struct buf *text, void *opaque) { 133 | if (text) man_text_escape(ob, text->data, text->size); } 134 | 135 | 136 | /* renderer structure */ 137 | struct mkd_renderer to_man = { 138 | /* document-level callbacks */ 139 | NULL, 140 | NULL, 141 | 142 | /* block-level callbacks */ 143 | man_blockcode, 144 | NULL, 145 | NULL, 146 | man_header, 147 | NULL, 148 | man_list, 149 | man_listitem, 150 | man_paragraph, 151 | NULL, 152 | NULL, 153 | NULL, 154 | 155 | /* span-level callbacks */ 156 | NULL, 157 | man_codespan, 158 | man_double_emphasis, 159 | man_emphasis, 160 | NULL, 161 | man_linebreak, 162 | NULL, 163 | NULL, 164 | NULL, 165 | 166 | /* low-level callbacks */ 167 | NULL, 168 | man_normal_text, 169 | 170 | /* renderer data */ 171 | 64, 172 | "*_", 173 | NULL }; 174 | 175 | 176 | 177 | /***************** 178 | * MAIN FUNCTION * 179 | *****************/ 180 | 181 | /* main • main function, interfacing STDIO with the parser */ 182 | int 183 | main(int argc, char **argv) { 184 | struct buf *ib, *ob; 185 | size_t ret; 186 | FILE *in = stdin; 187 | 188 | /* opening the file if given from the command line */ 189 | if (argc > 1) { 190 | in = fopen(argv[1], "r"); 191 | if (!in) { 192 | fprintf(stderr,"Unable to open input file \"%s\": %s\n", 193 | argv[1], strerror(errno)); 194 | return 1; } } 195 | 196 | /* reading everything */ 197 | ib = bufnew(READ_UNIT); 198 | bufgrow(ib, READ_UNIT); 199 | while ((ret = fread(ib->data + ib->size, 1, 200 | ib->asize - ib->size, in)) > 0) { 201 | ib->size += ret; 202 | bufgrow(ib, ib->size + READ_UNIT); } 203 | if (in != stdin) fclose(in); 204 | 205 | /* performing markdown to man */ 206 | ob = bufnew(OUTPUT_UNIT); 207 | markdown(ob, ib, &to_man); 208 | 209 | /* writing the result to stdout */ 210 | ret = fwrite(ob->data, 1, ob->size, stdout); 211 | if (ret < ob->size) 212 | fprintf(stderr, "Warning: only %zu output byte written, " 213 | "out of %zu\n", 214 | ret, 215 | ob->size); 216 | 217 | /* cleanup */ 218 | bufrelease(ib); 219 | bufrelease(ob); 220 | return 0; } 221 | 222 | /* vim: set filetype=c: */ 223 | -------------------------------------------------------------------------------- /test/element_tests.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2013 Uncodin, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #define BOOST_TEST_MODULE DocumentTests 18 | 19 | #include 20 | #include 21 | #include 22 | #include "element.h" 23 | 24 | using namespace Bypass; 25 | 26 | struct F { 27 | F() 28 | : element() 29 | { 30 | 31 | } 32 | 33 | ~F() { 34 | 35 | } 36 | 37 | Element element; 38 | }; 39 | 40 | BOOST_FIXTURE_TEST_CASE(element_initial_size, F) { 41 | BOOST_REQUIRE(element.size() == 0); 42 | } 43 | 44 | BOOST_FIXTURE_TEST_CASE(element_block_code_type, F) { 45 | element.setType(BLOCK_CODE); 46 | 47 | BOOST_REQUIRE(element.isBlockElement()); 48 | BOOST_REQUIRE(!element.isSpanElement()); 49 | } 50 | 51 | BOOST_FIXTURE_TEST_CASE(element_block_quote_type, F) { 52 | element.setType(BLOCK_QUOTE); 53 | 54 | BOOST_REQUIRE(element.isBlockElement()); 55 | BOOST_REQUIRE(!element.isSpanElement()); 56 | } 57 | 58 | BOOST_FIXTURE_TEST_CASE(element_block_html_type, F) { 59 | element.setType(BLOCK_HTML); 60 | 61 | BOOST_REQUIRE(element.isBlockElement()); 62 | BOOST_REQUIRE(!element.isSpanElement()); 63 | } 64 | 65 | BOOST_FIXTURE_TEST_CASE(element_header_type, F) { 66 | element.setType(HEADER); 67 | 68 | BOOST_REQUIRE(element.isBlockElement()); 69 | BOOST_REQUIRE(!element.isSpanElement()); 70 | } 71 | 72 | BOOST_FIXTURE_TEST_CASE(element_hrule_type, F) { 73 | element.setType(HRULE); 74 | 75 | BOOST_REQUIRE(element.isBlockElement()); 76 | BOOST_REQUIRE(!element.isSpanElement()); 77 | } 78 | 79 | BOOST_FIXTURE_TEST_CASE(element_list_type, F) { 80 | element.setType(LIST); 81 | 82 | BOOST_REQUIRE(element.isBlockElement()); 83 | BOOST_REQUIRE(!element.isSpanElement()); 84 | } 85 | 86 | BOOST_FIXTURE_TEST_CASE(element_list_item_type, F) { 87 | element.setType(LIST_ITEM); 88 | 89 | BOOST_REQUIRE(element.isBlockElement()); 90 | BOOST_REQUIRE(!element.isSpanElement()); 91 | } 92 | 93 | BOOST_FIXTURE_TEST_CASE(element_paragraph_type, F) { 94 | element.setType(PARAGRAPH); 95 | 96 | BOOST_REQUIRE(element.isBlockElement()); 97 | BOOST_REQUIRE(!element.isSpanElement()); 98 | } 99 | 100 | BOOST_FIXTURE_TEST_CASE(element_table_type, F) { 101 | element.setType(TABLE); 102 | 103 | BOOST_REQUIRE(element.isBlockElement()); 104 | BOOST_REQUIRE(!element.isSpanElement()); 105 | } 106 | 107 | BOOST_FIXTURE_TEST_CASE(element_table_cell_type, F) { 108 | element.setType(TABLE_CELL); 109 | 110 | BOOST_REQUIRE(element.isBlockElement()); 111 | BOOST_REQUIRE(!element.isSpanElement()); 112 | } 113 | 114 | BOOST_FIXTURE_TEST_CASE(element_table_row_type, F) { 115 | element.setType(TABLE_ROW); 116 | 117 | BOOST_REQUIRE(element.isBlockElement()); 118 | BOOST_REQUIRE(!element.isSpanElement()); 119 | } 120 | 121 | BOOST_FIXTURE_TEST_CASE(element_autolink_type, F) { 122 | element.setType(AUTOLINK); 123 | 124 | BOOST_REQUIRE(!element.isBlockElement()); 125 | BOOST_REQUIRE(element.isSpanElement()); 126 | } 127 | 128 | BOOST_FIXTURE_TEST_CASE(element_code_span_type, F) { 129 | element.setType(CODE_SPAN); 130 | 131 | BOOST_REQUIRE(!element.isBlockElement()); 132 | BOOST_REQUIRE(element.isSpanElement()); 133 | } 134 | 135 | BOOST_FIXTURE_TEST_CASE(element_double_emphasis_type, F) { 136 | element.setType(DOUBLE_EMPHASIS); 137 | 138 | BOOST_REQUIRE(!element.isBlockElement()); 139 | BOOST_REQUIRE(element.isSpanElement()); 140 | } 141 | 142 | BOOST_FIXTURE_TEST_CASE(element_emphasis_type, F) { 143 | element.setType(EMPHASIS); 144 | 145 | BOOST_REQUIRE(!element.isBlockElement()); 146 | BOOST_REQUIRE(element.isSpanElement()); 147 | } 148 | 149 | BOOST_FIXTURE_TEST_CASE(element_image_type, F) { 150 | element.setType(IMAGE); 151 | 152 | BOOST_REQUIRE(!element.isBlockElement()); 153 | BOOST_REQUIRE(element.isSpanElement()); 154 | } 155 | 156 | BOOST_FIXTURE_TEST_CASE(element_linebreak_type, F) { 157 | element.setType(LINEBREAK); 158 | 159 | BOOST_REQUIRE(!element.isBlockElement()); 160 | BOOST_REQUIRE(element.isSpanElement()); 161 | } 162 | 163 | BOOST_FIXTURE_TEST_CASE(element_link_type, F) { 164 | element.setType(LINK); 165 | 166 | BOOST_REQUIRE(!element.isBlockElement()); 167 | BOOST_REQUIRE(element.isSpanElement()); 168 | } 169 | 170 | BOOST_FIXTURE_TEST_CASE(element_raw_html_type, F) { 171 | element.setType(RAW_HTML_TAG); 172 | 173 | BOOST_REQUIRE(!element.isBlockElement()); 174 | BOOST_REQUIRE(element.isSpanElement()); 175 | } 176 | 177 | BOOST_FIXTURE_TEST_CASE(element_triple_emphasis_type, F) { 178 | element.setType(TRIPLE_EMPHASIS); 179 | 180 | BOOST_REQUIRE(!element.isBlockElement()); 181 | BOOST_REQUIRE(element.isSpanElement()); 182 | } 183 | 184 | BOOST_FIXTURE_TEST_CASE(element_append_single, F) { 185 | Element child; 186 | element.append(child); 187 | 188 | BOOST_REQUIRE(element.size() == 1); 189 | } 190 | 191 | BOOST_FIXTURE_TEST_CASE(element_access_single, F) { 192 | std::string expected = "child"; 193 | 194 | Element child; 195 | child.setText(expected); 196 | BOOST_REQUIRE(child.getText() == expected); 197 | 198 | element.append(child); 199 | 200 | BOOST_REQUIRE(element[0].getText() == expected); 201 | } 202 | 203 | BOOST_FIXTURE_TEST_CASE(element_append_multiple, F) { 204 | int i, count = 3; 205 | 206 | for (i = 0; i < count; i++) { 207 | Element child; 208 | 209 | char str[10]; 210 | sprintf(str, "%d", i); 211 | 212 | const std::string value = std::string(str); 213 | 214 | child.setText(value); 215 | element.append(child); 216 | } 217 | 218 | BOOST_REQUIRE(element[0].getText() == "0"); 219 | BOOST_REQUIRE(element[1].getText() == "1"); 220 | BOOST_REQUIRE(element[2].getText() == "2"); 221 | } 222 | 223 | BOOST_FIXTURE_TEST_CASE(element_add_attribute, F) { 224 | element.addAttribute("name", "value"); 225 | } 226 | 227 | BOOST_FIXTURE_TEST_CASE(element_get_attribute, F) { 228 | element.addAttribute("name", "value"); 229 | BOOST_REQUIRE(element.getAttribute("name") == "value"); 230 | } 231 | 232 | BOOST_FIXTURE_TEST_CASE(element_get_attribute_names_with_no_attributes, F) { 233 | BOOST_REQUIRE(element.attrSize() == 0); 234 | } 235 | 236 | BOOST_FIXTURE_TEST_CASE(element_get_attribute_names_with_multiple_attributes, F) { 237 | element.addAttribute("a", "A"); 238 | element.addAttribute("b", "B"); 239 | 240 | std::set res; 241 | Element::AttributeMap::iterator it = element.attrBegin(); 242 | for (; it != element.attrEnd(); ++it) { 243 | res.insert(it->first); 244 | } 245 | 246 | BOOST_REQUIRE(res.size() == 2); 247 | BOOST_REQUIRE(std::find(res.begin(), res.end(), "a") != res.end()); 248 | BOOST_REQUIRE(std::find(res.begin(), res.end(), "b") != res.end()); 249 | } 250 | 251 | -------------------------------------------------------------------------------- /platform/ios/BypassSample/BypassSample/en.lproj/MainStoryboard.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /platform/ios/Bypass/Bypass/BPElement.mm: -------------------------------------------------------------------------------- 1 | // 2 | // BPElement.m 3 | // Bypass 4 | // 5 | // Created by Damian Carrillo on 2/28/13. 6 | // Copyright 2013 Uncodin, Inc. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "BPElementPrivate.h" 22 | 23 | // Block Element Types 24 | 25 | const BPElementType BPBlockCode = Bypass::BLOCK_CODE; 26 | const BPElementType BPBlockQuote = Bypass::BLOCK_QUOTE; 27 | const BPElementType BPBlockHTML = Bypass::BLOCK_HTML; 28 | const BPElementType BPHeader = Bypass::HEADER; 29 | const BPElementType BPHRule = Bypass::HRULE; 30 | const BPElementType BPList = Bypass::LIST; 31 | const BPElementType BPListItem = Bypass::LIST_ITEM; 32 | const BPElementType BPParagraph = Bypass::PARAGRAPH; 33 | const BPElementType BPTable = Bypass::TABLE; 34 | const BPElementType BPTableCell = Bypass::TABLE_CELL; 35 | const BPElementType BPTableRow = Bypass::TABLE_ROW; 36 | 37 | // Span Element Types 38 | 39 | const BPElementType BPAutoLink = Bypass::AUTOLINK; 40 | const BPElementType BPCodeSpan = Bypass::CODE_SPAN; 41 | const BPElementType BPDoubleEmphasis = Bypass::DOUBLE_EMPHASIS; 42 | const BPElementType BPEmphasis = Bypass::EMPHASIS; 43 | const BPElementType BPImage = Bypass::IMAGE; 44 | const BPElementType BPLineBreak = Bypass::LINEBREAK; 45 | const BPElementType BPLink = Bypass::LINK; 46 | const BPElementType BPRawHTMLTag = Bypass::RAW_HTML_TAG; 47 | const BPElementType BPTripleEmphasis = Bypass::TRIPLE_EMPHASIS; 48 | const BPElementType BPText = Bypass::TEXT; 49 | const BPElementType BPStrikethrough = Bypass::STRIKETHROUGH; 50 | 51 | @interface BPElement () 52 | 53 | @end 54 | 55 | @implementation BPElement 56 | { 57 | Bypass::Element _element; 58 | NSString *_text; 59 | NSDictionary *_attributes; 60 | __weak BPElement *_parentElement; 61 | NSArray *_childElements; 62 | } 63 | 64 | - (id)init 65 | { 66 | Bypass::Element element; 67 | return [self initWithElement:element]; 68 | } 69 | 70 | - (id)initWithElement:(Bypass::Element)element 71 | { 72 | return [self initWithElement:element parentElement:nil]; 73 | } 74 | 75 | - (id)initWithElement:(Bypass::Element)element parentElement:(BPElement *)parentElement 76 | { 77 | self = [super init]; 78 | 79 | if (self != nil) { 80 | _element = element; 81 | _parentElement = parentElement; 82 | } 83 | 84 | return self; 85 | } 86 | 87 | - (BPElementType)elementType 88 | { 89 | return _element.getType(); 90 | } 91 | 92 | - (BOOL)isBlockElement 93 | { 94 | return _element.isBlockElement(); 95 | } 96 | 97 | - (NSString *)text 98 | { 99 | using namespace std; 100 | 101 | if (_text == nil) { 102 | string t = _element.getText(); 103 | 104 | if (t.length() > 0) { 105 | _text = [NSString stringWithCString:t.c_str() encoding:NSUTF8StringEncoding]; 106 | } 107 | } 108 | 109 | return _text; 110 | } 111 | 112 | - (NSDictionary *)attributes 113 | { 114 | using namespace Bypass; 115 | 116 | if (_attributes == nil) { 117 | Element::AttributeMap::iterator it = _element.attrBegin(); 118 | NSMutableDictionary *attributes; 119 | attributes = [NSMutableDictionary dictionaryWithCapacity:_element.attrSize()]; 120 | 121 | for (; it != _element.attrEnd(); ++it) { 122 | if (!it->first.empty() && !it->second.empty()) { 123 | NSString *nn = [NSString stringWithUTF8String:it->first.c_str()]; 124 | NSString *vv = [NSString stringWithUTF8String:it->second.c_str()]; 125 | 126 | [attributes setObject:vv forKey:nn]; 127 | } 128 | } 129 | 130 | _attributes = [NSDictionary dictionaryWithDictionary:attributes]; 131 | } 132 | 133 | return _attributes; 134 | } 135 | 136 | - (NSArray *)childElements 137 | { 138 | using namespace Bypass; 139 | 140 | if (_childElements == nil) { 141 | size_t i, count = _element.size(); 142 | 143 | NSMutableArray *childElements = [NSMutableArray arrayWithCapacity:count]; 144 | 145 | for (i = 0; i < count; ++i) { 146 | Element c = _element[i]; 147 | BPElement *cc = [[BPElement alloc] initWithElement:c parentElement:self]; 148 | childElements[i] = cc; 149 | } 150 | 151 | _childElements = [NSArray arrayWithArray:childElements]; 152 | } 153 | 154 | return _childElements; 155 | } 156 | 157 | #if __has_feature(objc_subscripting) 158 | 159 | - (id)objectAtIndexedSubscript:(NSUInteger)idx 160 | { 161 | return [[self childElements] objectAtIndexedSubscript:idx]; 162 | } 163 | 164 | - (id)objectForKeyedSubscript:(id)key 165 | { 166 | return [[self attributes] objectForKeyedSubscript:key]; 167 | } 168 | 169 | #endif 170 | 171 | - (NSString *)debugDescription 172 | { 173 | NSString *elementType; 174 | 175 | if ([self elementType] == BPBlockCode) { 176 | elementType = @"BPBlockCode"; 177 | } else if ([self elementType] == BPBlockQuote) { 178 | elementType = @"BPBlockQuote"; 179 | } else if ([self elementType] == BPBlockHTML) { 180 | elementType = @"BPBlockHTML"; 181 | } else if ([self elementType] == BPHeader) { 182 | elementType = @"BPHeader"; 183 | } else if ([self elementType] == BPHRule) { 184 | elementType = @"BPHRule"; 185 | } else if ([self elementType] == BPList) { 186 | elementType = @"BPList"; 187 | } else if ([self elementType] == BPListItem) { 188 | elementType = @"BPListItem"; 189 | } else if ([self elementType] == BPParagraph) { 190 | elementType = @"BPParagraph"; 191 | } else if ([self elementType] == BPTable) { 192 | elementType = @"BPTable"; 193 | } else if ([self elementType] == BPTableCell) { 194 | elementType = @"BPTableCell"; 195 | } else if ([self elementType] == BPTableRow) { 196 | elementType = @"BPTableRow"; 197 | } else if ([self elementType] == BPAutoLink) { 198 | elementType = @"BPAutoLink"; 199 | } else if ([self elementType] == BPCodeSpan) { 200 | elementType = @"BPCodeSpan"; 201 | } else if ([self elementType] == BPDoubleEmphasis) { 202 | elementType = @"BPDoubleEmphasis"; 203 | } else if ([self elementType] == BPEmphasis) { 204 | elementType = @"BPEmphasis"; 205 | } else if ([self elementType] == BPImage) { 206 | elementType = @"BPImage"; 207 | } else if ([self elementType] == BPLineBreak) { 208 | elementType = @"BPLineBreak"; 209 | } else if ([self elementType] == BPLink) { 210 | elementType = @"BPLink"; 211 | } else if ([self elementType] == BPRawHTMLTag) { 212 | elementType = @"BPRawHTMLTag"; 213 | } else if ([self elementType] == BPTripleEmphasis) { 214 | elementType = @"BPTripleEmphasis"; 215 | } else if ([self elementType] == BPText) { 216 | elementType = @"BPText"; 217 | } else if ([self elementType] == BPStrikethrough) { 218 | elementType = @"BPStrikethrough"; 219 | } 220 | 221 | NSMutableString *desc = [NSMutableString stringWithString:NSStringFromClass([self class])]; 222 | [desc appendFormat:@"{ type: %@", elementType]; 223 | [desc appendFormat:@", text: %@", [self text]]; 224 | [desc appendFormat:@", attributes: %@", [[self attributes] debugDescription]]; 225 | [desc appendString:@", childElements: {"]; 226 | 227 | for (BPElement *childElement in [self childElements]) { 228 | [desc appendFormat:@"%@\n", [childElement debugDescription]]; 229 | } 230 | 231 | [desc appendString:@"}"]; 232 | [desc appendString:@"}"]; 233 | return desc; 234 | } 235 | 236 | @end 237 | -------------------------------------------------------------------------------- /dep/libsoldout/buffer.c: -------------------------------------------------------------------------------- 1 | /* buffer.c - automatic buffer structure */ 2 | 3 | /* 4 | * Copyright (c) 2008, Natacha Porté 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | /* 20 | * COMPILE TIME OPTIONS 21 | * 22 | * BUFFER_STATS • if defined, stats are kept about memory usage 23 | */ 24 | #define BUFFER_STATS 25 | 26 | #define BUFFER_STDARG 27 | 28 | #include "buffer.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | /******************** 36 | * GLOBAL VARIABLES * 37 | ********************/ 38 | 39 | #ifdef BUFFER_STATS 40 | long buffer_stat_nb = 0; 41 | size_t buffer_stat_alloc_bytes = 0; 42 | #endif 43 | 44 | 45 | /*************************** 46 | * STATIC HELPER FUNCTIONS * 47 | ***************************/ 48 | 49 | /* lower • retruns the lower-case variant of the input char */ 50 | static char 51 | lower(char c) { 52 | return (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c; } 53 | 54 | 55 | 56 | /******************** 57 | * BUFFER FUNCTIONS * 58 | ********************/ 59 | 60 | /* bufcasecmp • case-insensitive buffer comparison */ 61 | int 62 | bufcasecmp(const struct buf *a, const struct buf *b) { 63 | size_t i = 0; 64 | size_t cmplen; 65 | if (a == b) return 0; 66 | if (!a) return -1; else if (!b) return 1; 67 | cmplen = (a->size < b->size) ? a->size : b->size; 68 | while (i < cmplen && lower(a->data[i]) == lower(b->data[i])) ++i; 69 | if (i < a->size) { 70 | if (i < b->size) return lower(a->data[i]) - lower(b->data[i]); 71 | else return 1; } 72 | else { if (i < b->size) return -1; 73 | else return 0; } } 74 | 75 | 76 | /* bufcmp • case-sensitive buffer comparison */ 77 | int 78 | bufcmp(const struct buf *a, const struct buf *b) { 79 | size_t i = 0; 80 | size_t cmplen; 81 | if (a == b) return 0; 82 | if (!a) return -1; else if (!b) return 1; 83 | cmplen = (a->size < b->size) ? a->size : b->size; 84 | while (i < cmplen && a->data[i] == b->data[i]) ++i; 85 | if (i < a->size) { 86 | if (i < b->size) return a->data[i] - b->data[i]; 87 | else return 1; } 88 | else { if (i < b->size) return -1; 89 | else return 0; } } 90 | 91 | 92 | /* bufcmps • case-sensitive comparison of a string to a buffer */ 93 | int 94 | bufcmps(const struct buf *a, const char *b) { 95 | const size_t len = strlen(b); 96 | size_t cmplen = len; 97 | int r; 98 | if (!a || !a->size) return b ? 0 : -1; 99 | if (len < a->size) cmplen = a->size; 100 | r = strncmp(a->data, b, cmplen); 101 | if (r) return r; 102 | else if (a->size == len) return 0; 103 | else if (a->size < len) return -1; 104 | else return 1; } 105 | 106 | 107 | /* bufdup • buffer duplication */ 108 | struct buf * 109 | bufdup(const struct buf *src, size_t dupunit) { 110 | size_t blocks; 111 | struct buf *ret; 112 | if (src == 0) return 0; 113 | ret = malloc(sizeof (struct buf)); 114 | if (ret == 0) return 0; 115 | ret->unit = dupunit; 116 | ret->size = src->size; 117 | ret->ref = 1; 118 | if (!src->size) { 119 | ret->asize = 0; 120 | ret->data = 0; 121 | return ret; } 122 | blocks = (src->size + dupunit - 1) / dupunit; 123 | ret->asize = blocks * dupunit; 124 | ret->data = malloc(ret->asize); 125 | if (ret->data == 0) { 126 | free(ret); 127 | return 0; } 128 | memcpy(ret->data, src->data, src->size); 129 | #ifdef BUFFER_STATS 130 | buffer_stat_nb += 1; 131 | buffer_stat_alloc_bytes += ret->asize; 132 | #endif 133 | return ret; } 134 | 135 | 136 | /* bufgrow • increasing the allocated size to the given value */ 137 | int 138 | bufgrow(struct buf *buf, size_t neosz) { 139 | size_t neoasz; 140 | void *neodata; 141 | if (!buf || !buf->unit) return 0; 142 | if (buf->asize >= neosz) return 1; 143 | neoasz = buf->asize + buf->unit; 144 | while (neoasz < neosz) neoasz += buf->unit; 145 | neodata = realloc(buf->data, neoasz); 146 | if (!neodata) return 0; 147 | #ifdef BUFFER_STATS 148 | buffer_stat_alloc_bytes += (neoasz - buf->asize); 149 | #endif 150 | buf->data = neodata; 151 | buf->asize = neoasz; 152 | return 1; } 153 | 154 | 155 | /* bufnew • allocation of a new buffer */ 156 | struct buf * 157 | bufnew(size_t unit) { 158 | struct buf *ret; 159 | ret = malloc(sizeof (struct buf)); 160 | if (ret) { 161 | #ifdef BUFFER_STATS 162 | buffer_stat_nb += 1; 163 | #endif 164 | ret->data = 0; 165 | ret->size = ret->asize = 0; 166 | ret->ref = 1; 167 | ret->unit = unit; } 168 | return ret; } 169 | 170 | 171 | /* bufnullterm • NUL-termination of the string array (making a C-string) */ 172 | void 173 | bufnullterm(struct buf *buf) { 174 | if (!buf || !buf->unit) return; 175 | if (buf->size < buf->asize && buf->data[buf->size] == 0) return; 176 | if (buf->size + 1 <= buf->asize || bufgrow(buf, buf->size + 1)) 177 | buf->data[buf->size] = 0; } 178 | 179 | 180 | /* bufprintf • formatted printing to a buffer */ 181 | void 182 | bufprintf(struct buf *buf, const char *fmt, ...) { 183 | va_list ap; 184 | if (!buf || !buf->unit) return; 185 | va_start(ap, fmt); 186 | vbufprintf(buf, fmt, ap); 187 | va_end(ap); } 188 | 189 | 190 | /* bufput • appends raw data to a buffer */ 191 | void 192 | bufput(struct buf *buf, const void *data, size_t len) { 193 | if (!buf) return; 194 | if (buf->size + len > buf->asize && !bufgrow(buf, buf->size + len)) 195 | return; 196 | memcpy(buf->data + buf->size, data, len); 197 | buf->size += len; } 198 | 199 | 200 | /* bufputs • appends a NUL-terminated string to a buffer */ 201 | void 202 | bufputs(struct buf *buf, const char *str) { 203 | bufput(buf, str, strlen (str)); } 204 | 205 | 206 | /* bufputc • appends a single char to a buffer */ 207 | void 208 | bufputc(struct buf *buf, char c) { 209 | if (!buf) return; 210 | if (buf->size + 1 > buf->asize && !bufgrow(buf, buf->size + 1)) 211 | return; 212 | buf->data[buf->size] = c; 213 | buf->size += 1; } 214 | 215 | 216 | /* bufrelease • decrease the reference count and free the buffer if needed */ 217 | void 218 | bufrelease(struct buf *buf) { 219 | if (!buf || !buf->unit) return; 220 | buf->ref -= 1; 221 | if (buf->ref == 0) { 222 | #ifdef BUFFER_STATS 223 | buffer_stat_nb -= 1; 224 | buffer_stat_alloc_bytes -= buf->asize; 225 | #endif 226 | free(buf->data); 227 | free(buf); } } 228 | 229 | 230 | /* bufreset • frees internal data of the buffer */ 231 | void 232 | bufreset(struct buf *buf) { 233 | if (!buf || !buf->unit || !buf->asize) return; 234 | #ifdef BUFFER_STATS 235 | buffer_stat_alloc_bytes -= buf->asize; 236 | #endif 237 | free(buf->data); 238 | buf->data = 0; 239 | buf->size = buf->asize = 0; } 240 | 241 | 242 | /* bufset • safely assigns a buffer to another */ 243 | void 244 | bufset(struct buf **dest, struct buf *src) { 245 | if (src) { 246 | if (!src->asize) src = bufdup(src, 1); 247 | else src->ref += 1; } 248 | bufrelease(*dest); 249 | *dest = src; } 250 | 251 | 252 | /* bufslurp • removes a given number of bytes from the head of the array */ 253 | void 254 | bufslurp(struct buf *buf, size_t len) { 255 | if (!buf || !buf->unit || len <= 0) return; 256 | if (len >= buf->size) { 257 | buf->size = 0; 258 | return; } 259 | buf->size -= len; 260 | memmove(buf->data, buf->data + len, buf->size); } 261 | 262 | 263 | /* buftoi • converts the numbers at the beginning of the buf into an int */ 264 | int 265 | buftoi(struct buf *buf, size_t offset_i, size_t *offset_o) { 266 | int r = 0, neg = 0; 267 | size_t i = offset_i; 268 | if (!buf || !buf->size) return 0; 269 | if (buf->data[i] == '+') i += 1; 270 | else if (buf->data[i] == '-') { 271 | neg = 1; 272 | i += 1; } 273 | while (i < buf->size && buf->data[i] >= '0' && buf->data[i] <= '9') { 274 | r = (r * 10) + buf->data[i] - '0'; 275 | i += 1; } 276 | if (offset_o) *offset_o = i; 277 | return neg ? -r : r; } 278 | 279 | 280 | 281 | /* vbufprintf • stdarg variant of formatted printing into a buffer */ 282 | void 283 | vbufprintf(struct buf *buf, const char *fmt, va_list ap) { 284 | int n; 285 | va_list ap_save; 286 | if (buf == 0 287 | || (buf->size >= buf->asize && !bufgrow (buf, buf->size + 1))) 288 | return; 289 | va_copy(ap_save, ap); 290 | n = vsnprintf(buf->data + buf->size, buf->asize - buf->size, fmt, ap); 291 | if (n >= buf->asize - buf->size) { 292 | if (buf->size + n + 1 > buf->asize 293 | && !bufgrow (buf, buf->size + n + 1)) 294 | return; 295 | n = vsnprintf (buf->data + buf->size, 296 | buf->asize - buf->size, fmt, ap_save); } 297 | va_end(ap_save); 298 | if (n < 0) return; 299 | buf->size += n; } 300 | 301 | /* vim: set filetype=c: */ 302 | -------------------------------------------------------------------------------- /dep/libsoldout/array.c: -------------------------------------------------------------------------------- 1 | /* array.c - automatic dynamic array for pointers */ 2 | 3 | /* 4 | * Copyright (c) 2008, Natacha Porté 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "array.h" 20 | 21 | #include 22 | 23 | 24 | /*************************** 25 | * STATIC HELPER FUNCTIONS * 26 | ***************************/ 27 | 28 | /* arr_realloc • realloc memory of a struct array */ 29 | static int 30 | arr_realloc(struct array* arr, int neosz) { 31 | void* neo; 32 | neo = realloc(arr->base, neosz * arr->unit); 33 | if (neo == 0) return 0; 34 | arr->base = neo; 35 | arr->asize = neosz; 36 | if (arr->size > neosz) arr->size = neosz; 37 | return 1; } 38 | 39 | 40 | /* parr_realloc • realloc memory of a struct parray */ 41 | static int 42 | parr_realloc(struct parray* arr, int neosz) { 43 | void* neo; 44 | neo = realloc(arr->item, neosz * sizeof (void*)); 45 | if (neo == 0) return 0; 46 | arr->item = neo; 47 | arr->asize = neosz; 48 | if (arr->size > neosz) arr->size = neosz; 49 | return 1; } 50 | 51 | 52 | 53 | /*************************** 54 | * GENERIC ARRAY FUNCTIONS * 55 | ***************************/ 56 | 57 | /* arr_adjust • shrink the allocated memory to fit exactly the needs */ 58 | int 59 | arr_adjust(struct array *arr) { 60 | return arr_realloc(arr, arr->size); } 61 | 62 | 63 | /* arr_free • frees the structure contents (buf NOT the struct itself) */ 64 | void 65 | arr_free(struct array *arr) { 66 | if (!arr) return; 67 | free(arr->base); 68 | arr->base = 0; 69 | arr->size = arr->asize = 0; } 70 | 71 | 72 | /* arr_grow • increases the array size to fit the given number of elements */ 73 | int 74 | arr_grow(struct array *arr, int need) { 75 | if (arr->asize >= need) return 1; 76 | else return arr_realloc(arr, need); } 77 | 78 | 79 | /* arr_init • initialization of the contents of the struct */ 80 | void 81 | arr_init(struct array *arr, size_t unit) { 82 | arr->base = 0; 83 | arr->size = arr->asize = 0; 84 | arr->unit = unit; } 85 | 86 | 87 | /* arr_insert • inserting nb elements before the nth one */ 88 | int 89 | arr_insert(struct array *arr, int nb, int n) { 90 | char *src, *dst; 91 | size_t len; 92 | if (!arr || nb <= 0 || n < 0 93 | || !arr_grow(arr, arr->size + nb)) 94 | return 0; 95 | if (n < arr->size) { 96 | src = arr->base; 97 | src += n * arr->unit; 98 | dst = src + nb * arr->unit; 99 | len = (arr->size - n) * arr->unit; 100 | memmove(dst, src, len); } 101 | arr->size += nb; 102 | return 1; } 103 | 104 | 105 | /* arr_item • returns a pointer to the n-th element */ 106 | void * 107 | arr_item(struct array *arr, int no) { 108 | char *ptr; 109 | if (!arr || no < 0 || no >= arr->size) return 0; 110 | ptr = arr->base; 111 | ptr += no * arr->unit; 112 | return ptr; } 113 | 114 | 115 | /* arr_newitem • returns the index of a new element appended to the array */ 116 | int 117 | arr_newitem(struct array *arr) { 118 | if (!arr_grow(arr, arr->size + 1)) return -1; 119 | arr->size += 1; 120 | return arr->size - 1; } 121 | 122 | 123 | /* arr_remove • removes the n-th elements of the array */ 124 | void 125 | arr_remove(struct array *arr, int idx) { 126 | if (!arr || idx < 0 || idx >= arr->size) return; 127 | arr->size -= 1; 128 | if (idx < arr->size) { 129 | char *dst = arr->base; 130 | char *src; 131 | dst += idx * arr->unit; 132 | src = dst + arr->unit; 133 | memmove(dst, src, (arr->size - idx) * arr->unit); } } 134 | 135 | 136 | /* arr_sorted_find • O(log n) search in a sorted array, returning entry */ 137 | void * 138 | arr_sorted_find(struct array *arr, void *key, array_cmp_fn cmp) { 139 | int mi, ma, cu, ret; 140 | char *ptr = arr->base; 141 | mi = -1; 142 | ma = arr->size; 143 | while (mi < ma - 1) { 144 | cu = mi + (ma - mi) / 2; 145 | ret = cmp(key, ptr + cu * arr->unit); 146 | if (ret == 0) return ptr + cu * arr->unit; 147 | else if (ret < 0) ma = cu; 148 | else /* if (ret > 0) */ mi = cu; } 149 | return 0; } 150 | 151 | 152 | /* arr_sorted_find_i • O(log n) search in a sorted array, 153 | * returning index of the smallest element larger than the key */ 154 | int 155 | arr_sorted_find_i(struct array *arr, void *key, array_cmp_fn cmp) { 156 | int mi, ma, cu, ret; 157 | char *ptr = arr->base; 158 | mi = -1; 159 | ma = arr->size; 160 | while (mi < ma - 1) { 161 | cu = mi + (ma - mi) / 2; 162 | ret = cmp(key, ptr + cu * arr->unit); 163 | if (ret == 0) { 164 | while (cu < arr->size && ret == 0) { 165 | cu += 1; 166 | ret = cmp(key, ptr + cu * arr->unit); } 167 | return cu; } 168 | else if (ret < 0) ma = cu; 169 | else /* if (ret > 0) */ mi = cu; } 170 | return ma; } 171 | 172 | 173 | 174 | /*************************** 175 | * POINTER ARRAY FUNCTIONS * 176 | ***************************/ 177 | 178 | /* parr_adjust • shrinks the allocated memory to fit exactly the needs */ 179 | int 180 | parr_adjust(struct parray* arr) { 181 | return parr_realloc (arr, arr->size); } 182 | 183 | 184 | /* parr_free • frees the structure contents (buf NOT the struct itself) */ 185 | void 186 | parr_free(struct parray *arr) { 187 | if (!arr) return; 188 | free (arr->item); 189 | arr->item = 0; 190 | arr->size = 0; 191 | arr->asize = 0; } 192 | 193 | 194 | /* parr_grow • increases the array size to fit the given number of elements */ 195 | int 196 | parr_grow(struct parray *arr, int need) { 197 | if (arr->asize >= need) return 1; 198 | else return parr_realloc (arr, need); } 199 | 200 | 201 | /* parr_init • initialization of the struct (which is equivalent to zero) */ 202 | void 203 | parr_init(struct parray *arr) { 204 | arr->item = 0; 205 | arr->size = 0; 206 | arr->asize = 0; } 207 | 208 | 209 | /* parr_insert • inserting nb elements before the nth one */ 210 | int 211 | parr_insert(struct parray *parr, int nb, int n) { 212 | char *src, *dst; 213 | size_t len, i; 214 | if (!parr || nb <= 0 || n < 0 215 | || !parr_grow(parr, parr->size + nb)) 216 | return 0; 217 | if (n < parr->size) { 218 | src = (void *)parr->item; 219 | src += n * sizeof (void *); 220 | dst = src + nb * sizeof (void *); 221 | len = (parr->size - n) * sizeof (void *); 222 | memmove(dst, src, len); 223 | for (i = 0; i < nb; ++i) 224 | parr->item[n + i] = 0; } 225 | parr->size += nb; 226 | return 1; } 227 | 228 | 229 | /* parr_pop • pops the last item of the array and returns it */ 230 | void * 231 | parr_pop(struct parray *arr) { 232 | if (arr->size <= 0) return 0; 233 | arr->size -= 1; 234 | return arr->item[arr->size]; } 235 | 236 | 237 | /* parr_push • pushes a pointer at the end of the array (= append) */ 238 | int 239 | parr_push(struct parray *arr, void *i) { 240 | if (!parr_grow(arr, arr->size + 1)) return 0; 241 | arr->item[arr->size] = i; 242 | arr->size += 1; 243 | return 1; } 244 | 245 | 246 | /* parr_remove • removes the n-th element of the array and returns it */ 247 | void * 248 | parr_remove(struct parray *arr, int idx) { 249 | void* ret; 250 | int i; 251 | if (!arr || idx < 0 || idx >= arr->size) return 0; 252 | ret = arr->item[idx]; 253 | for (i = idx+1; i < arr->size; ++i) 254 | arr->item[i - 1] = arr->item[i]; 255 | arr->size -= 1; 256 | return ret; } 257 | 258 | 259 | /* parr_sorted_find • O(log n) search in a sorted array, returning entry */ 260 | void * 261 | parr_sorted_find(struct parray *arr, void *key, array_cmp_fn cmp) { 262 | int mi, ma, cu, ret; 263 | mi = -1; 264 | ma = arr->size; 265 | while (mi < ma - 1) { 266 | cu = mi + (ma - mi) / 2; 267 | ret = cmp(key, arr->item[cu]); 268 | if (ret == 0) return arr->item[cu]; 269 | else if (ret < 0) ma = cu; 270 | else /* if (ret > 0) */ mi = cu; } 271 | return 0; } 272 | 273 | 274 | /* parr_sorted_find_i • O(log n) search in a sorted array, 275 | * returning index of the smallest element larger than the key */ 276 | int 277 | parr_sorted_find_i(struct parray *arr, void *key, array_cmp_fn cmp) { 278 | int mi, ma, cu, ret; 279 | mi = -1; 280 | ma = arr->size; 281 | while (mi < ma - 1) { 282 | cu = mi + (ma - mi) / 2; 283 | ret = cmp(key, arr->item[cu]); 284 | if (ret == 0) { 285 | while (cu < arr->size && ret == 0) { 286 | cu += 1; 287 | ret = cmp(key, arr->item[cu]); } 288 | return cu; } 289 | else if (ret < 0) ma = cu; 290 | else /* if (ret > 0) */ mi = cu; } 291 | return ma; } 292 | 293 | 294 | /* parr_top • returns the top the stack (i.e. the last element of the array) */ 295 | void * 296 | parr_top(struct parray *arr) { 297 | if (arr == 0 || arr->size <= 0) return 0; 298 | else return arr->item[arr->size - 1]; } 299 | 300 | /* vim: set filetype=c: */ 301 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------