Ejemplo n.º 1
0
        /// <summary>
        /// Display help tab.
        /// </summary>
        /// <returns>Help tab view.</returns>
        public async Task <ActionResult> Index()
        {
            string helpTabText = await this.configurationProvider.GetSavedEntityDetailAsync(ConfigurationEntityTypes.HelpTabText).ConfigureAwait(false);

            var marked = new MarkedNet.Marked();

            return(this.View(nameof(this.Index)));
        }
        private string MarkdownToHTML(string rawMarkdown)
        {
            string markdownCSSPath = Path.Combine(NSBundle.MainBundle.BundlePath, "SyntaxHighlighting/github-markdown.css");
            string parsedMarkdown  = new MarkedNet.Marked().Parse(rawMarkdown);

            string markdowntHTML = "<!doctype html>" +
                                   "<head>" +
                                   "<link rel=\"stylesheet\" href=\"" +
                                   markdownCSSPath +
                                   "\" />" +
                                   "<meta name=\"viewport\" content=\"width=" +
                                   UIScreen.MainScreen.Bounds.Width.ToString() +
                                   ", shrink-to-fit=YES\">" +
                                   "</head>" +
                                   "<body class=\"markdown-body\">" +
                                   parsedMarkdown +
                                   "</body>";

            return(markdowntHTML);
        }
        public static string MarkdownToHTML(string rawMarkdown, UITraitCollection collection)
        {
            bool darkMode = CheckDarkMode(collection);

            string markdownFile = darkMode ? _darkMarkdownFile : _lightMarkdownFile;

            string markdownCSSPath = Path.Combine(NSBundle.MainBundle.BundlePath, $"SyntaxHighlighting/{markdownFile}");
            string parsedMarkdown  = new MarkedNet.Marked().Parse(rawMarkdown);

            string markdowntHTML = "<!doctype html>" +
                                   "<head>" +
                                   "<link rel=\"stylesheet\" href=\"" +
                                   markdownCSSPath +
                                   "\" />" +
                                   "<meta name=\"viewport\" content=\"width=" +
                                   UIScreen.MainScreen.Bounds.Width.ToString() +
                                   ", shrink-to-fit=YES\">" +
                                   "</head>" +
                                   "<body class=\"markdown-body\">" +
                                   parsedMarkdown +
                                   "</body>";

            return(markdowntHTML);
        }
Ejemplo n.º 4
0
        private void Initialize()
        {
            CheckDarkMode();

            // Build out readme html.
            try
            {
                string markdownFile = _darkMode ? _darkMarkdownFile : _lightMarkdownFile;

                string readmePath    = Path.Combine(NSBundle.MainBundle.BundlePath, "Samples", _info.Category, _info.FormalName, "readme.md");
                string readmeCSSPath = Path.Combine(NSBundle.MainBundle.BundlePath, $"SyntaxHighlighting/{markdownFile}");
                string readmeContent = new MarkedNet.Marked().Parse(File.ReadAllText(readmePath));

                string readmeHTML = "<!doctype html><head><base href=\"" +
                                    readmePath +
                                    "\"><link rel=\"stylesheet\" href=\"" +
                                    readmeCSSPath +
                                    "\" />" +
                                    "<meta name=\"viewport\" content=\"width=" +
                                    UIScreen.MainScreen.Bounds.Width.ToString() +
                                    ", shrink-to-fit=YES\">" +
                                    "</head>" +
                                    "<body class=\"markdown-body\">" +
                                    readmeContent +
                                    "</body>";

                // Load the readme into the webview.
                _readmeView.LoadHtmlString(readmeHTML, new NSUrl(_contentDirectoryPath, true));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                _readmeView.LoadHtmlString("Could not load information.", new NSUrl(_contentDirectoryPath, true));
            }

            // Build out source code html.
            try
            {
                string syntaxFile = _darkMode ? _darkSyntaxFile : _lightSyntaxFile;

                // Get the paths for the .css and .js files for syntax highlighting.
                string syntaxHighlightCSS = Path.Combine(NSBundle.MainBundle.BundlePath, $"SyntaxHighlighting/{syntaxFile}");
                string jsPath             = Path.Combine(NSBundle.MainBundle.BundlePath, "SyntaxHighlighting/highlight.pack.js");

                // Start and end HTML tags.
                const string _sourceHTMLStart =
                    "<html>" +
                    "<head>" +
                    "<link rel=\"stylesheet\" href=\"{csspath}\">" +
                    "<script type=\"text/javascript\" src=\"{jspath}\"></script>" +
                    "<script>hljs.initHighlightingOnLoad();</script>" +
                    "</head>" +
                    "<body>" +
                    "<pre>";

                const string _sourceHTMLEnd =
                    "</pre>" +
                    "</body>" +
                    "</html>";

                string sourceFilesPath = Path.Combine(NSBundle.MainBundle.BundlePath, "Samples", _info.Category, _info.FormalName);

                // Create a dictionary of the files.
                _sourceCodeFiles = new Dictionary <string, string>();

                // Loop over every source code file in the sample directory.
                foreach (string sourceCodePath in Directory.GetFiles(sourceFilesPath, "*.cs"))
                {
                    // Get the code as a string.
                    string baseContent = File.ReadAllText(sourceCodePath);

                    // Build the html.
                    string sourceCodeHTML =
                        _sourceHTMLStart.Replace("{csspath}", syntaxHighlightCSS).Replace("{jspath}", jsPath) +
                        "<code class=\"csharp\">" +
                        baseContent +
                        "</code>" +
                        _sourceHTMLEnd;

                    // Get the filename without the full path.
                    string shortPath = sourceCodePath.Split('/').Last();

                    // Add the html to the source code files dictionary.
                    _sourceCodeFiles.Add(shortPath, sourceCodeHTML);
                }

                // Load the first source code file into the web view.
                string firstKey = _sourceCodeFiles.Keys.First();
                _codeWebView.LoadHtmlString(_sourceCodeFiles[firstKey], new NSUrl(_contentDirectoryPath, true));
                _codeButton.Title = firstKey;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                _codeWebView.LoadHtmlString("Could not load source code.", new NSUrl(_contentDirectoryPath, true));
                _codeButton.Enabled = false;
            }
        }