public void GetToken_ReturnLinkToken_WhenTextContainsOneLinkTag() { var mark = new LinkMark(); var expectedToken = new TokenMd("#aaaaa", mark); var tags = new Dictionary <Mark, IMarkParser>(); var parser = new MarkdownParser(tags); var tokens = parser.GetTokens("#aaaaa"); tokens.First().Token.Should().BeEquivalentTo(expectedToken.Token); }
protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state) { PropertyDescriptor property = context.DataContext.GetProperties()[WordCreate.GetWordAppTag]; Application wordApp = property.GetValue(context.DataContext) as Application; try { string linkName = LinkName.Get(context); string linkMark = LinkMark.Get(context); string linkAddr = LinkAddr.Get(context); string bookMark = BookMark.Get(context); string pic = Pic.Get(context); if (linkName != null) { Hyperlinks links = wordApp.Selection.Hyperlinks; links.Add(wordApp.Selection.Range, linkAddr, linkMark, "", linkName, linkMark); } if (bookMark != null) { Bookmarks bookmarks = wordApp.Selection.Bookmarks; bookmarks.Add(bookMark); } if (pic != null) { InlineShapes lineshapes = wordApp.Selection.InlineShapes; InlineShape lineshape = lineshapes.AddPicture(pic); } } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "Word执行过程出错", e.Message); CommonVariable.realaseProcessExit(wordApp); } m_Delegate = new runDelegate(Run); return(m_Delegate.BeginInvoke(callback, state)); }
public TokenMd GetToken(string text, int index, out int finalIndex) { link = default; linkText = default; finalIndex = index; builder = new StringBuilder(); mark = new LinkMark(); helper = new ParseHelper(); isFirst = true; symbolsCount = 0; currentSymbol = "["; var isLink = true; while (finalIndex < text.Length) { if (isFirst && text[finalIndex] != '[') { isLink = false; } var resToken = HandleSquareBrackets(text, index, finalIndex, out finalIndex); if (resToken != null) { isLink = false; } resToken = HandleOpenRoundBrackets(text, index, finalIndex, out finalIndex); if (resToken != null) { isLink = false; } if (text[finalIndex] == ')' && currentSymbol == "(") { link = builder.ToString(); finalIndex += 2; symbolsCount++; mark.LinkText = linkText; mark.Link = link; if (string.IsNullOrEmpty(linkText) && string.IsNullOrEmpty(link)) { isLink = false; } if (symbolsCount == mark.AllSymbols.Length) { if (isLink) { return(new TokenMd(linkText, mark)); } var tokenText = text.Substring(index, finalIndex - index); return(new TokenMd(tokenText, new EmptyMark())); } } var resultText = text.Substring(index, finalIndex - index); return(new TokenMd(resultText, new EmptyMark())); } return(new TokenMd(text.Substring(index, finalIndex - index), new EmptyMark())); }